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
commit dcb28fd061
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

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