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:
Clyybber 2021-05-09 00:56:37 +02:00 • committed by GitHub
commit 72d6b59ffa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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)