treetab: tiny cleanup (#17929)
* treetab: tiny cleanup * Another tiny thing * Explicitly move n Co-authored-by: Andreas Rumpf <rumpf_a@web.de> * Typo Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
This commit is contained in:
parent
4e0f38fbb1
commit
72d6b59ffa
1 changed files with 4 additions and 6 deletions
|
|
@ -86,12 +86,11 @@ proc nodeTablePut*(t: var TNodeTable, key: PNode, val: int) =
|
||||||
t.data[index].val = val
|
t.data[index].val = val
|
||||||
else:
|
else:
|
||||||
if mustRehash(t.data.len, t.counter):
|
if mustRehash(t.data.len, t.counter):
|
||||||
var n: TNodePairSeq
|
var n = newSeq[TNodePair](t.data.len * GrowthFactor)
|
||||||
newSeq(n, t.data.len * GrowthFactor)
|
|
||||||
for i in 0..high(t.data):
|
for i in 0..high(t.data):
|
||||||
if t.data[i].key != nil:
|
if t.data[i].key != nil:
|
||||||
nodeTableRawInsert(n, t.data[i].h, t.data[i].key, t.data[i].val)
|
nodeTableRawInsert(n, t.data[i].h, t.data[i].key, t.data[i].val)
|
||||||
swap(t.data, n)
|
t.data = move n
|
||||||
nodeTableRawInsert(t.data, k, key, val)
|
nodeTableRawInsert(t.data, k, key, val)
|
||||||
inc(t.counter)
|
inc(t.counter)
|
||||||
|
|
||||||
|
|
@ -103,12 +102,11 @@ proc nodeTableTestOrSet*(t: var TNodeTable, key: PNode, val: int): int =
|
||||||
result = t.data[index].val
|
result = t.data[index].val
|
||||||
else:
|
else:
|
||||||
if mustRehash(t.data.len, t.counter):
|
if mustRehash(t.data.len, t.counter):
|
||||||
var n: TNodePairSeq
|
var n = newSeq[TNodePair](t.data.len * GrowthFactor)
|
||||||
newSeq(n, t.data.len * GrowthFactor)
|
|
||||||
for i in 0..high(t.data):
|
for i in 0..high(t.data):
|
||||||
if t.data[i].key != nil:
|
if t.data[i].key != nil:
|
||||||
nodeTableRawInsert(n, t.data[i].h, t.data[i].key, t.data[i].val)
|
nodeTableRawInsert(n, t.data[i].h, t.data[i].key, t.data[i].val)
|
||||||
swap(t.data, n)
|
t.data = move n
|
||||||
nodeTableRawInsert(t.data, k, key, val)
|
nodeTableRawInsert(t.data, k, key, val)
|
||||||
result = val
|
result = val
|
||||||
inc(t.counter)
|
inc(t.counter)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue