[minor]break loops after a candidate is added to seqs (#18770)

* [minor]break loops when added

* Update compiler/lookups.nim

Co-authored-by: Clyybber <darkmine956@gmail.com>

Co-authored-by: Clyybber <darkmine956@gmail.com>
This commit is contained in:
flywind 2021-08-31 19:32:37 +08:00 • committed by GitHub
commit 8f4bdb3596
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -211,14 +211,16 @@ proc debugScopes*(c: PContext; limit=0, max = int.high) {.deprecated.} =
proc searchInScopesFilterBy*(c: PContext, s: PIdent, filter: TSymKinds): seq[PSym] = proc searchInScopesFilterBy*(c: PContext, s: PIdent, filter: TSymKinds): seq[PSym] =
result = @[] result = @[]
for scope in allScopes(c.currentScope): block outer:
var ti: TIdentIter for scope in allScopes(c.currentScope):
var candidate = initIdentIter(ti, scope.symbols, s) var ti: TIdentIter
while candidate != nil: var candidate = initIdentIter(ti, scope.symbols, s)
if candidate.kind in filter: while candidate != nil:
if result.len == 0: if candidate.kind in filter:
result.add candidate result.add candidate
candidate = nextIdentIter(ti, scope.symbols) # Break here, because further symbols encountered would be shadowed
break outer
candidate = nextIdentIter(ti, scope.symbols)
if result.len == 0: if result.len == 0:
var marked = initIntSet() var marked = initIntSet()