refactor cmpNimIdentifier (#16611)
* refactor cmpNimIdentifier * Apply suggestions from code review Co-authored-by: Clyybber <darkmine956@gmail.com> Co-authored-by: Clyybber <darkmine956@gmail.com>
This commit is contained in:
parent
61fd19c7e6
commit
b727217229
3 changed files with 7 additions and 9 deletions
|
|
@ -1437,12 +1437,9 @@ when defined(nimVmEqIdent):
|
||||||
## these nodes will be unwrapped.
|
## these nodes will be unwrapped.
|
||||||
|
|
||||||
else:
|
else:
|
||||||
from std/private/strimpl import cmpIgnoreStyleImpl
|
from std/private/strimpl import cmpNimIdentifier
|
||||||
# this procedure is optimized for native code, it should not be compiled to nimVM bytecode.
|
|
||||||
proc cmpIgnoreStyle(a, b: cstring): int {.noSideEffect.} =
|
|
||||||
cmpIgnoreStyleImpl(a, b, true)
|
|
||||||
|
|
||||||
proc eqIdent*(a, b: string): bool = cmpIgnoreStyle(a, b) == 0
|
proc eqIdent*(a, b: string): bool = cmpNimIdentifier(a, b) == 0
|
||||||
## Check if two idents are equal.
|
## Check if two idents are equal.
|
||||||
|
|
||||||
proc eqIdent*(node: NimNode; s: string): bool {.compileTime.} =
|
proc eqIdent*(node: NimNode; s: string): bool {.compileTime.} =
|
||||||
|
|
|
||||||
|
|
@ -91,7 +91,7 @@ when not defined(gcDestructors):
|
||||||
else:
|
else:
|
||||||
include system/seqs_v2_reimpl
|
include system/seqs_v2_reimpl
|
||||||
|
|
||||||
from std/private/strimpl import cmpIgnoreStyleImpl
|
from std/private/strimpl import cmpNimIdentifier
|
||||||
|
|
||||||
when not defined(js):
|
when not defined(js):
|
||||||
template rawType(x: Any): PNimType =
|
template rawType(x: Any): PNimType =
|
||||||
|
|
@ -368,9 +368,6 @@ iterator fields*(x: Any): tuple[name: string, any: Any] =
|
||||||
for name, any in items(ret):
|
for name, any in items(ret):
|
||||||
yield ($name, any)
|
yield ($name, any)
|
||||||
|
|
||||||
proc cmpNimIdentifier(a, b: cstring): int {.noSideEffect.} =
|
|
||||||
cmpIgnoreStyleImpl(a, b, true)
|
|
||||||
|
|
||||||
proc getFieldNode(p: pointer, n: ptr TNimNode,
|
proc getFieldNode(p: pointer, n: ptr TNimNode,
|
||||||
name: cstring): ptr TNimNode =
|
name: cstring): ptr TNimNode =
|
||||||
case n.kind
|
case n.kind
|
||||||
|
|
|
||||||
|
|
@ -70,3 +70,7 @@ template endsWithImpl*[T: string | cstring](s, suffix: T) =
|
||||||
if s[i+j] != suffix[i]: return false
|
if s[i+j] != suffix[i]: return false
|
||||||
inc(i)
|
inc(i)
|
||||||
if i >= suffixLen: return true
|
if i >= suffixLen: return true
|
||||||
|
|
||||||
|
|
||||||
|
func cmpNimIdentifier*[T: string | cstring](a, b: T): int =
|
||||||
|
cmpIgnoreStyleImpl(a, b, true)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue