cache rope when threads are enabled (#19981)

* cache rope

* add threadvar
This commit is contained in:
flywind
2022-07-07 20:14:05 +08:00
committed by GitHub
parent 430a179307
commit dcb28fd061

View File

@@ -86,13 +86,12 @@ proc newRope(data: string = ""): Rope =
result.L = -data.len
result.data = data
when not compileOption("threads"):
var
cache: array[0..2048*2 - 1, Rope]
var
cache {.threadvar.} : array[0..2048*2 - 1, Rope]
proc resetRopeCache* =
for i in low(cache)..high(cache):
cache[i] = nil
proc resetRopeCache* =
for i in low(cache)..high(cache):
cache[i] = nil
proc ropeInvariant(r: Rope): bool =
if r == nil: