Skip to content

Commit 9a971f3

Browse files
authored
feat: performance array improvement by 11x (#358)
* feat: performance array improvement * fix: clean comment * fix: review
1 parent ffed186 commit 9a971f3

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

index.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -956,9 +956,6 @@ function buildArray (location, code, name, key = null) {
956956
}
957957
`
958958
}
959-
code += `
960-
var json = '['
961-
`
962959
const laterCode = ''
963960

964961
// default to any items type
@@ -1020,17 +1017,19 @@ function buildArray (location, code, name, key = null) {
10201017

10211018
code += `
10221019
var l = obj.length
1023-
1020+
var jsonOutput=''
1021+
var jsonLastChar
10241022
for (var i = 0; i < l; i++) {
1025-
var jsonLastChar = json[json.length - 1]
1023+
var json = ''
10261024
1027-
if (i > 0 && jsonLastChar !== '[' && jsonLastChar !== ',') {
1025+
if (jsonLastChar && jsonLastChar.length && jsonLastChar !== ',') {
10281026
json += ','
10291027
}
10301028
${result.code}
1029+
jsonLastChar = json.slice(-1)
1030+
jsonOutput += json
10311031
}
1032-
json += ']'
1033-
return json
1032+
return \`[\${jsonOutput}]\`
10341033
}
10351034
${result.laterCode}
10361035
`

0 commit comments

Comments
 (0)