less copy tree (#11249)

This commit is contained in:
Arne Döring 2019-05-15 12:11:03 +02:00 • committed by GitHub
commit 5e68d8f9e9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -668,12 +668,12 @@ proc getConstExpr(m: PSym, n: PNode; g: ModuleGraph): PNode =
if a != nil: if a != nil:
result = n result = n
n.sons[0] = a n.sons[0] = a
of nkBracket: of nkBracket, nkCurly:
result = copyTree(n) result = copyNode(n)
for i in 0 ..< sonsLen(n): for i, son in n.pairs:
var a = getConstExpr(m, n.sons[i], g) var a = getConstExpr(m, son, g)
if a == nil: return nil if a == nil: return nil
result.sons[i] = a result.add a
incl(result.flags, nfAllConst) incl(result.flags, nfAllConst)
of nkRange: of nkRange:
var a = getConstExpr(m, n.sons[0], g) var a = getConstExpr(m, n.sons[0], g)
@ -683,13 +683,6 @@ proc getConstExpr(m: PSym, n: PNode; g: ModuleGraph): PNode =
result = copyNode(n) result = copyNode(n)
addSon(result, a) addSon(result, a)
addSon(result, b) addSon(result, b)
of nkCurly:
result = copyTree(n)
for i in 0 ..< sonsLen(n):
var a = getConstExpr(m, n.sons[i], g)
if a == nil: return nil
result.sons[i] = a
incl(result.flags, nfAllConst)
#of nkObjConstr: #of nkObjConstr:
# result = copyTree(n) # result = copyTree(n)
# for i in 1 ..< sonsLen(n): # for i in 1 ..< sonsLen(n):
@ -699,17 +692,20 @@ proc getConstExpr(m: PSym, n: PNode; g: ModuleGraph): PNode =
# incl(result.flags, nfAllConst) # incl(result.flags, nfAllConst)
of nkPar, nkTupleConstr: of nkPar, nkTupleConstr:
# tuple constructor # tuple constructor
result = copyTree(n) result = copyNode(n)
if (sonsLen(n) > 0) and (n.sons[0].kind == nkExprColonExpr): if (sonsLen(n) > 0) and (n.sons[0].kind == nkExprColonExpr):
for i in 0 ..< sonsLen(n): for i, expr in n.pairs:
var a = getConstExpr(m, n.sons[i].sons[1], g) let exprNew = copyNode(expr) # nkExprColonExpr
exprNew.add expr[0]
let a = getConstExpr(m, expr[1], g)
if a == nil: return nil if a == nil: return nil
result.sons[i].sons[1] = a exprNew.add a
result.add exprNew
else: else:
for i in 0 ..< sonsLen(n): for i, expr in n.pairs:
var a = getConstExpr(m, n.sons[i], g) let a = getConstExpr(m, expr, g)
if a == nil: return nil if a == nil: return nil
result.sons[i] = a result.add a
incl(result.flags, nfAllConst) incl(result.flags, nfAllConst)
of nkChckRangeF, nkChckRange64, nkChckRange: of nkChckRangeF, nkChckRange64, nkChckRange:
var a = getConstExpr(m, n.sons[0], g) var a = getConstExpr(m, n.sons[0], g)