Skip to content

Commit

Permalink
revert last commit
Browse files Browse the repository at this point in the history
  • Loading branch information
planetis-m committed May 1, 2024
1 parent 0643e61 commit 39b54bb
Showing 1 changed file with 8 additions and 20 deletions.
28 changes: 8 additions & 20 deletions src/jsonpak/private/rawops.nim
Original file line number Diff line number Diff line change
Expand Up @@ -60,19 +60,13 @@ proc rawAddKeyValuePair*(result: var JsonTree, src, dest: NodePos, key: string)
let L = span(result, src.int) + 1
let oldfull = result.nodes.len
setLen(result.nodes, oldfull+L)
when nimvm:
for i in countdown(oldfull-1, dest.int):
result.nodes[i+L] = result.nodes[i]
else:
moveMem(addr result.nodes[dest.int+L], addr result.nodes[dest.int], (oldfull-dest.int)*sizeof(Node))
for i in countdown(oldfull-1, dest.int):
result.nodes[i+L] = result.nodes[i]
result.nodes[dest.int] = toAtomNode(result, opcodeString, key)
let src =
if src >= dest: NodePos(src.int+L) else: src
when nimvm:
for i in 0..<L-1:
result.nodes[dest.int+i+1] = result.nodes[src.int+i]
else:
moveMem(addr result.nodes[dest.int+1], addr result.nodes[src.int], (L-1)*sizeof(Node))
for i in 0..<L-1:
result.nodes[dest.int+i+1] = result.nodes[src.int+i]

proc rawAddKeyValuePair*(result: var JsonTree, tree: JsonTree, n: NodePos, key: string) =
privateAccess(JsonTree)
Expand Down Expand Up @@ -126,18 +120,12 @@ proc rawReplace*(result: var JsonTree, tree: JsonTree, n: NodePos) =
if diff > 0:
# Expand the nodes sequence if the new value is larger
setLen(result.nodes, oldfull+diff)
when nimvm:
for i in countdown(oldfull-1, endpos):
result.nodes[i+diff] = result.nodes[i]
else:
moveMem(addr result.nodes[endpos+diff], addr result.nodes[endpos], (oldfull-endpos)*sizeof(Node))
for i in countdown(oldfull-1, endpos):
result.nodes[i+diff] = result.nodes[i]
elif diff < 0:
# Shrink the nodes sequence if the new value is smaller
when nimvm:
for i in countup(endpos, oldfull-1):
result.nodes[i+diff] = result.nodes[i]
else:
moveMem(addr result.nodes[endpos+diff], addr result.nodes[endpos], (oldfull-endpos)*sizeof(Node))
for i in countup(endpos, oldfull-1):
result.nodes[i+diff] = result.nodes[i]
setLen(result.nodes, oldfull+diff)
# Copy the new nodes into the nodes sequence
for i in 0..<L:
Expand Down

0 comments on commit 39b54bb

Please sign in to comment.