diff options
author | flywind <xzsflywind@gmail.com> | 2021-08-31 19:32:37 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-31 13:32:37 +0200 |
commit | 8f4bdb3596bb7650f2688b8243dc3164abfc21c9 (patch) | |
tree | d71453d52902eadf4eb803c85fc1e310a2cc88e1 /compiler | |
parent | f02de25ca1b660b0b6e1ae2d4981106744814fe3 (diff) | |
download | Nim-8f4bdb3596bb7650f2688b8243dc3164abfc21c9.tar.gz |
[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>
Diffstat (limited to 'compiler')
-rw-r--r-- | compiler/lookups.nim | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/compiler/lookups.nim b/compiler/lookups.nim index 4c072eed8..fc30408e5 100644 --- a/compiler/lookups.nim +++ b/compiler/lookups.nim @@ -211,14 +211,16 @@ proc debugScopes*(c: PContext; limit=0, max = int.high) {.deprecated.} = proc searchInScopesFilterBy*(c: PContext, s: PIdent, filter: TSymKinds): seq[PSym] = result = @[] - for scope in allScopes(c.currentScope): - var ti: TIdentIter - var candidate = initIdentIter(ti, scope.symbols, s) - while candidate != nil: - if candidate.kind in filter: - if result.len == 0: + block outer: + for scope in allScopes(c.currentScope): + var ti: TIdentIter + var candidate = initIdentIter(ti, scope.symbols, s) + while candidate != nil: + if candidate.kind in filter: 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: var marked = initIntSet() |