Cosmetic compiler cleanup (#12718)

* Cleanup compiler code base

* Unify add calls

* Unify len invocations

* Unify range operators

* Fix oversight

* Remove {.procvar.} pragma

* initCandidate -> newCandidate where reasonable

* Unify safeLen calls
This commit is contained in:
Clyybber 2019-11-28 17:13:04 +01:00 • committed by Andreas Rumpf
commit 7e747d11c6
109 changed files with 6115 additions and 6254 deletions

View file

@ -31,8 +31,8 @@ proc hashTree(n: PNode): Hash =
of nkStrLit..nkTripleStrLit:
result = result !& hash(n.strVal)
else:
for i in 0 ..< len(n):
result = result !& hashTree(n.sons[i])
for i in 0..<n.len:
result = result !& hashTree(n[i])
proc treesEquivalent(a, b: PNode): bool =
if a == b:
@ -46,9 +46,9 @@ proc treesEquivalent(a, b: PNode): bool =
of nkFloatLit..nkFloat64Lit: result = a.floatVal == b.floatVal
of nkStrLit..nkTripleStrLit: result = a.strVal == b.strVal
else:
if len(a) == len(b):
for i in 0 ..< len(a):
if not treesEquivalent(a.sons[i], b.sons[i]): return
if a.len == b.len:
for i in 0..<a.len:
if not treesEquivalent(a[i], b[i]): return
result = true
if result: result = sameTypeOrNil(a.typ, b.typ)
@ -82,9 +82,9 @@ proc nodeTablePut*(t: var TNodeTable, key: PNode, val: int) =
assert(t.data[index].key != nil)
t.data[index].val = val
else:
if mustRehash(len(t.data), t.counter):
newSeq(n, len(t.data) * GrowthFactor)
for i in 0 .. high(t.data):
if mustRehash(t.data.len, t.counter):
newSeq(n, t.data.len * GrowthFactor)
for i in 0..high(t.data):
if t.data[i].key != nil:
nodeTableRawInsert(n, t.data[i].h, t.data[i].key, t.data[i].val)
swap(t.data, n)
@ -99,9 +99,9 @@ proc nodeTableTestOrSet*(t: var TNodeTable, key: PNode, val: int): int =
assert(t.data[index].key != nil)
result = t.data[index].val
else:
if mustRehash(len(t.data), t.counter):
newSeq(n, len(t.data) * GrowthFactor)
for i in 0 .. high(t.data):
if mustRehash(t.data.len, t.counter):
newSeq(n, t.data.len * GrowthFactor)
for i in 0..high(t.data):
if t.data[i].key != nil:
nodeTableRawInsert(n, t.data[i].h, t.data[i].key, t.data[i].val)
swap(t.data, n)