* try using endsWith * use memcmp * add cache * cleanup * better * minor * fix * improve test coverage for methods with ARC
This commit is contained in:
parent
ef4ac5a0d2
commit
8bfc396a4d
9 changed files with 45 additions and 7 deletions
|
|
@ -1615,8 +1615,11 @@ proc genNewFinalize(p: BProc, e: PNode) =
|
||||||
|
|
||||||
proc genOfHelper(p: BProc; dest: PType; a: Rope; info: TLineInfo): Rope =
|
proc genOfHelper(p: BProc; dest: PType; a: Rope; info: TLineInfo): Rope =
|
||||||
if optTinyRtti in p.config.globalOptions:
|
if optTinyRtti in p.config.globalOptions:
|
||||||
result = ropecg(p.module, "#isObj($1.m_type, $2)",
|
let ti = genTypeInfo2Name(p.module, dest)
|
||||||
[a, genTypeInfo2Name(p.module, dest)])
|
inc p.module.labels
|
||||||
|
let cache = "Nim_OfCheck_CACHE" & p.module.labels.rope
|
||||||
|
p.module.s[cfsVars].addf("static TNimTypeV2* $#[2];$n", [cache])
|
||||||
|
result = ropecg(p.module, "#isObjWithCache($#.m_type, $#, $#)", [a, ti, cache])
|
||||||
else:
|
else:
|
||||||
# unfortunately 'genTypeInfoV1' sets tfObjHasKids as a side effect, so we
|
# unfortunately 'genTypeInfoV1' sets tfObjHasKids as a side effect, so we
|
||||||
# have to call it here first:
|
# have to call it here first:
|
||||||
|
|
|
||||||
|
|
@ -227,10 +227,34 @@ template tearDownForeignThreadGc* =
|
||||||
## With `--gc:arc` a nop.
|
## With `--gc:arc` a nop.
|
||||||
discard
|
discard
|
||||||
|
|
||||||
proc isObj(obj: PNimTypeV2, subclass: cstring): bool {.compilerRtl, inl.} =
|
type ObjCheckCache = array[0..1, PNimTypeV2]
|
||||||
proc strstr(s, sub: cstring): cstring {.header: "<string.h>", importc.}
|
|
||||||
|
|
||||||
result = strstr(obj.name, subclass) != nil
|
proc memcmp(str1, str2: cstring, n: csize_t): cint {.importc, header: "<string.h>".}
|
||||||
|
|
||||||
|
func endsWith(s, suffix: cstring): bool {.inline.} =
|
||||||
|
let
|
||||||
|
sLen = s.len
|
||||||
|
suffixLen = suffix.len
|
||||||
|
|
||||||
|
if suffixLen <= sLen:
|
||||||
|
result = memcmp(cstring(addr s[sLen - suffixLen]), suffix, csize_t(suffixLen)) == 0
|
||||||
|
|
||||||
|
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 chckObj(obj: PNimTypeV2, subclass: cstring) {.compilerRtl.} =
|
proc chckObj(obj: PNimTypeV2, subclass: cstring) {.compilerRtl.} =
|
||||||
# checks if obj is of type subclass:
|
# checks if obj is of type subclass:
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
discard """
|
discard """
|
||||||
output: '''
|
matrix: "--mm:arc; --mm:refc"
|
||||||
|
output: '''
|
||||||
proc Base
|
proc Base
|
||||||
proc Child
|
proc Child
|
||||||
method Base
|
method Base
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
discard """
|
discard """
|
||||||
|
matrix: "--mm:arc; --mm:refc"
|
||||||
output: '''wow2
|
output: '''wow2
|
||||||
X 1
|
X 1
|
||||||
X 3'''
|
X 3'''
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
discard """
|
discard """
|
||||||
|
matrix: "--mm:arc; --mm:refc"
|
||||||
output: '''
|
output: '''
|
||||||
wof!
|
wof!
|
||||||
wof!
|
wof!
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
discard """
|
discard """
|
||||||
|
matrix: "--mm:arc; --mm:refc"
|
||||||
output: '''
|
output: '''
|
||||||
do nothing
|
do nothing
|
||||||
HELLO WORLD!
|
HELLO WORLD!
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
discard """
|
discard """
|
||||||
cmd: "nim c --multimethods:off $file"
|
matrix: "--mm:arc --multimethods:off; --mm:refc --multimethods:off"
|
||||||
output: '''base
|
output: '''base
|
||||||
base
|
base
|
||||||
base
|
base
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,7 @@
|
||||||
|
discard """
|
||||||
|
matrix: "--mm:arc; --mm:refc"
|
||||||
|
"""
|
||||||
|
|
||||||
type Input[T] = object
|
type Input[T] = object
|
||||||
toks: seq[T]
|
toks: seq[T]
|
||||||
index: int
|
index: int
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,6 @@
|
||||||
|
discard """
|
||||||
|
matrix: "--mm:arc; --mm:refc"
|
||||||
|
"""
|
||||||
|
|
||||||
type SomeBase* = ref object of RootObj
|
type SomeBase* = ref object of RootObj
|
||||||
type SomeDerived* = ref object of SomeBase
|
type SomeDerived* = ref object of SomeBase
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue