Skip to content

Commit b727217

Browse files
ringaboutClyybber
andauthored
refactor cmpNimIdentifier (#16611)
* refactor cmpNimIdentifier * Apply suggestions from code review Co-authored-by: Clyybber <[email protected]> Co-authored-by: Clyybber <[email protected]>
1 parent 61fd19c commit b727217

File tree

3 files changed

+7
-9
lines changed

3 files changed

+7
-9
lines changed

lib/core/macros.nim

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1437,12 +1437,9 @@ when defined(nimVmEqIdent):
14371437
## these nodes will be unwrapped.
14381438

14391439
else:
1440-
from std/private/strimpl import cmpIgnoreStyleImpl
1441-
# this procedure is optimized for native code, it should not be compiled to nimVM bytecode.
1442-
proc cmpIgnoreStyle(a, b: cstring): int {.noSideEffect.} =
1443-
cmpIgnoreStyleImpl(a, b, true)
1440+
from std/private/strimpl import cmpNimIdentifier
14441441

1445-
proc eqIdent*(a, b: string): bool = cmpIgnoreStyle(a, b) == 0
1442+
proc eqIdent*(a, b: string): bool = cmpNimIdentifier(a, b) == 0
14461443
## Check if two idents are equal.
14471444

14481445
proc eqIdent*(node: NimNode; s: string): bool {.compileTime.} =

lib/core/typeinfo.nim

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ when not defined(gcDestructors):
9191
else:
9292
include system/seqs_v2_reimpl
9393

94-
from std/private/strimpl import cmpIgnoreStyleImpl
94+
from std/private/strimpl import cmpNimIdentifier
9595

9696
when not defined(js):
9797
template rawType(x: Any): PNimType =
@@ -368,9 +368,6 @@ iterator fields*(x: Any): tuple[name: string, any: Any] =
368368
for name, any in items(ret):
369369
yield ($name, any)
370370

371-
proc cmpNimIdentifier(a, b: cstring): int {.noSideEffect.} =
372-
cmpIgnoreStyleImpl(a, b, true)
373-
374371
proc getFieldNode(p: pointer, n: ptr TNimNode,
375372
name: cstring): ptr TNimNode =
376373
case n.kind

lib/std/private/strimpl.nim

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,7 @@ template endsWithImpl*[T: string | cstring](s, suffix: T) =
7070
if s[i+j] != suffix[i]: return false
7171
inc(i)
7272
if i >= suffixLen: return true
73+
74+
75+
func cmpNimIdentifier*[T: string | cstring](a, b: T): int =
76+
cmpIgnoreStyleImpl(a, b, true)

0 commit comments

Comments
 (0)