remove when declared(cache); cache is always there (#19991)

This commit is contained in:
flywind 2022-07-10 15:37:15 +08:00 • committed by GitHub
commit ed2bf02a51
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -111,16 +111,13 @@ var gCacheMisses* = 0
var gCacheIntTries* = 0 var gCacheIntTries* = 0
proc insertInCache(s: string): Rope = proc insertInCache(s: string): Rope =
when declared(cache): inc gCacheTries
inc gCacheTries var h = hash(s) and high(cache)
var h = hash(s) and high(cache) result = cache[h]
result = cache[h] if isNil(result) or result.data != s:
if isNil(result) or result.data != s: inc gCacheMisses
inc gCacheMisses
result = newRope(s)
cache[h] = result
else:
result = newRope(s) result = newRope(s)
cache[h] = result
proc rope*(s: string): Rope = proc rope*(s: string): Rope =
## Converts a string to a rope. ## Converts a string to a rope.