diff options
Diffstat (limited to 'compiler/treetab.nim')
-rw-r--r-- | compiler/treetab.nim | 30 |
1 files changed, 18 insertions, 12 deletions
diff --git a/compiler/treetab.nim b/compiler/treetab.nim index 31cc76366..6685c4a89 100644 --- a/compiler/treetab.nim +++ b/compiler/treetab.nim @@ -9,8 +9,12 @@ # Implements a table from trees to trees. Does structural equivalence checking. -import - hashes, ast, astalgo, types +import ast, astalgo, types + +import std/hashes + +when defined(nimPreviewSlimSystem): + import std/assertions proc hashTree*(n: PNode): Hash = if n.isNil: @@ -54,7 +58,11 @@ proc treesEquivalent(a, b: PNode): bool = for i in 0..<a.len: if not treesEquivalent(a[i], b[i]): return result = true + else: + result = false if result: result = sameTypeOrNil(a.typ, b.typ) + else: + result = false proc nodeTableRawGet(t: TNodeTable, k: Hash, key: PNode): int = var h: Hash = k and high(t.data) @@ -79,36 +87,34 @@ proc nodeTableRawInsert(data: var TNodePairSeq, k: Hash, key: PNode, data[h].val = val proc nodeTablePut*(t: var TNodeTable, key: PNode, val: int) = - var n: TNodePairSeq - var k: Hash = hashTree(key) - var index = nodeTableRawGet(t, k, key) + let k = hashTree(key) + let index = nodeTableRawGet(t, k, key) if index >= 0: assert(t.data[index].key != nil) t.data[index].val = val else: if mustRehash(t.data.len, t.counter): - newSeq(n, t.data.len * GrowthFactor) + var n = newSeq[TNodePair](t.data.len * GrowthFactor) for i in 0..high(t.data): if t.data[i].key != nil: 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) inc(t.counter) proc nodeTableTestOrSet*(t: var TNodeTable, key: PNode, val: int): int = - var n: TNodePairSeq - var k: Hash = hashTree(key) - var index = nodeTableRawGet(t, k, key) + let k = hashTree(key) + let index = nodeTableRawGet(t, k, key) if index >= 0: assert(t.data[index].key != nil) result = t.data[index].val else: if mustRehash(t.data.len, t.counter): - newSeq(n, t.data.len * GrowthFactor) + var n = newSeq[TNodePair](t.data.len * GrowthFactor) for i in 0..high(t.data): if t.data[i].key != nil: 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) result = val inc(t.counter) |