try to optimize hot spots for orc-booting compiler (#20001)

* optimize hot spots fro orc-booting compiler

* remove GC_ref

* minor

* remove comments

* Revert "minor"

This reverts commit 4965a190a2d6457044faa1442795e55bdad57602.

* emulate cursor
This commit is contained in:
flywind 2022-07-12 19:07:18 +08:00 • committed by GitHub
commit a97b00ad8d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -18,6 +18,9 @@ import
when defined(nimPreviewSlimSystem): when defined(nimPreviewSlimSystem):
import std/assertions import std/assertions
when not defined(nimHasCursor):
{.pragma: cursor.}
proc hashNode*(p: RootRef): Hash proc hashNode*(p: RootRef): Hash
proc treeToYaml*(conf: ConfigRef; n: PNode, indent: int = 0, maxRecDepth: int = - 1): Rope proc treeToYaml*(conf: ConfigRef; n: PNode, indent: int = 0, maxRecDepth: int = - 1): Rope
# Convert a tree into its YAML representation; this is used by the # Convert a tree into its YAML representation; this is used by the
@ -815,16 +818,21 @@ type
name*: PIdent name*: PIdent
proc nextIdentIter*(ti: var TIdentIter, tab: TStrTable): PSym = proc nextIdentIter*(ti: var TIdentIter, tab: TStrTable): PSym =
# hot spots
var h = ti.h and high(tab.data) var h = ti.h and high(tab.data)
var start = h var start = h
result = tab.data[h] var p {.cursor.} = tab.data[h]
while result != nil: while p != nil:
if result.name.id == ti.name.id: break if p.name.id == ti.name.id: break
h = nextTry(h, high(tab.data)) h = nextTry(h, high(tab.data))
if h == start: if h == start:
result = nil p = nil
break break
result = tab.data[h] p = tab.data[h]
if p != nil:
result = p # increase the count
else:
result = nil
ti.h = nextTry(h, high(tab.data)) ti.h = nextTry(h, high(tab.data))
proc initIdentIter*(ti: var TIdentIter, tab: TStrTable, s: PIdent): PSym = proc initIdentIter*(ti: var TIdentIter, tab: TStrTable, s: PIdent): PSym =