Skip to content

Commit bcb7d9e

Browse files
committed
impr(ast): parse float/int and string were too slow!
1 parent d02caf5 commit bcb7d9e

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

Python/ast.nim

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1028,21 +1028,20 @@ ast atom, [AsdlExpr]:
10281028

10291029
of Token.NUMBER:
10301030
# float
1031-
for c in child1.tokenNode.content:
1032-
if not (c in '0'..'9'):
1033-
let f = parseFloat(child1.tokenNode.content)
1034-
let pyFloat = newPyFloat(f)
1035-
result = newAstConstant(pyFloat)
1031+
if not child1.tokenNode.content.allCharsInSet({'0'..'9'}):
1032+
let f = parseFloat(child1.tokenNode.content)
1033+
let pyFloat = newPyFloat(f)
1034+
result = newAstConstant(pyFloat)
10361035
# int
1037-
if result.isNil:
1036+
else:
10381037
let pyInt = newPyInt(child1.tokenNode.content)
10391038
result = newAstConstant(pyInt)
10401039

10411040
of Token.STRING:
1042-
var strSeq: seq[string]
1041+
var str: string
10431042
for child in parseNode.children:
1044-
strSeq.add(child.tokenNode.content)
1045-
let pyString = newPyString(strSeq.join())
1043+
str.add(child.tokenNode.content)
1044+
let pyString = newPyString(str)
10461045
result = newAstConstant(pyString)
10471046

10481047
of Token.True:

0 commit comments

Comments
 (0)