diff options
Diffstat (limited to 'compiler/btrees.nim')
-rw-r--r-- | compiler/btrees.nim | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/compiler/btrees.nim b/compiler/btrees.nim index 5f78c07fe..3b737b1bc 100644 --- a/compiler/btrees.nim +++ b/compiler/btrees.nim @@ -10,13 +10,16 @@ ## BTree implementation with few features, but good enough for the ## Nim compiler's needs. +when defined(nimPreviewSlimSystem): + import std/assertions + const M = 512 # max children per B-tree node = M-1 # (must be even and greater than 2) Mhalf = M div 2 type - Node[Key, Val] = ref object + Node[Key, Val] {.acyclic.} = ref object entries: int keys: array[M, Key] case isInternal: bool @@ -35,6 +38,7 @@ template less(a, b): bool = cmp(a, b) < 0 template eq(a, b): bool = cmp(a, b) == 0 proc getOrDefault*[Key, Val](b: BTree[Key, Val], key: Key): Val = + result = default(Val) var x = b.root while x.isInternal: for j in 0..<x.entries: @@ -65,7 +69,10 @@ proc copyHalf[Key, Val](h, result: Node[Key, Val]) = result.links[j] = h.links[Mhalf + j] else: for j in 0..<Mhalf: - shallowCopy(result.vals[j], h.vals[Mhalf + j]) + when defined(gcArc) or defined(gcOrc) or defined(gcAtomicArc): + result.vals[j] = move h.vals[Mhalf + j] + else: + shallowCopy(result.vals[j], h.vals[Mhalf + j]) proc split[Key, Val](h: Node[Key, Val]): Node[Key, Val] = ## split node in half @@ -85,7 +92,10 @@ proc insert[Key, Val](h: Node[Key, Val], key: Key, val: Val): Node[Key, Val] = if less(key, h.keys[j]): break inc j for i in countdown(h.entries, j+1): - shallowCopy(h.vals[i], h.vals[i-1]) + when defined(gcArc) or defined(gcOrc) or defined(gcAtomicArc): + h.vals[i] = move h.vals[i-1] + else: + shallowCopy(h.vals[i], h.vals[i-1]) h.vals[j] = val else: var newLink: Node[Key, Val] = nil |