implements display based subtype checking (6.4x faster without threads; 2.8x faster with threads) (#20781)
* WIP: fast 'of' operator based on the literature * implement display based subtype checking Co-authored-by: Araq <rumpf_a@web.de>
This commit is contained in:
parent
ca3b6cba5d
commit
7d15fdd375
5 changed files with 83 additions and 52 deletions
|
|
@ -227,8 +227,6 @@ template tearDownForeignThreadGc* =
|
|||
## With `--gc:arc` a nop.
|
||||
discard
|
||||
|
||||
type ObjCheckCache = array[0..1, PNimTypeV2]
|
||||
|
||||
proc memcmp(str1, str2: cstring, n: csize_t): cint {.importc, header: "<string.h>".}
|
||||
|
||||
func endsWith(s, suffix: cstring): bool {.inline.} =
|
||||
|
|
@ -242,19 +240,8 @@ func endsWith(s, suffix: cstring): bool {.inline.} =
|
|||
proc isObj(obj: PNimTypeV2, subclass: cstring): bool {.compilerRtl, inl.} =
|
||||
result = endsWith(obj.name, subclass)
|
||||
|
||||
proc isObjSlowPath(obj: PNimTypeV2, subclass: cstring, cache: var ObjCheckCache): bool {.compilerRtl, inline.} =
|
||||
if endsWith(obj.name, subclass):
|
||||
cache[1] = obj
|
||||
result = true
|
||||
else:
|
||||
cache[0] = obj
|
||||
result = false
|
||||
|
||||
proc isObjWithCache(obj: PNimTypeV2, subclass: cstring, cache: var ObjCheckCache): bool {.compilerRtl.} =
|
||||
if cache[0] == obj: result = false
|
||||
elif cache[1] == obj: result = true
|
||||
else:
|
||||
result = isObjSlowPath(obj, subclass, cache)
|
||||
proc isObjDisplayCheck(source: PNimTypeV2, targetDepth: int16, token: uint32): bool {.compilerRtl, inline.} =
|
||||
result = targetDepth <= source.depth and source.display[targetDepth] == token
|
||||
|
||||
proc chckObj(obj: PNimTypeV2, subclass: cstring) {.compilerRtl.} =
|
||||
# checks if obj is of type subclass:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue