Skip to content

Commit 838e37b

Browse files
authored
perf(serializer): optimize array serialization by removing arrayEnd check
Signed-off-by: francesco <francesco.bagnoli.69@gmail.com>
1 parent a08113e commit 838e37b

1 file changed

Lines changed: 7 additions & 7 deletions

File tree

index.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -587,10 +587,10 @@ function buildArray (context, location) {
587587
functionCode += `
588588
if (${i} < arrayLength) {
589589
if (${buildArrayTypeCondition(item.type, value)}) {
590-
${tmpRes}
591-
if (${i} < arrayEnd) {
590+
if (${i}) {
592591
json += JSON_STR_COMMA
593592
}
593+
${tmpRes}
594594
} else {
595595
throw new Error(\`Item at ${i} does not match schema definition.\`)
596596
}
@@ -601,21 +601,21 @@ function buildArray (context, location) {
601601
if (schema.additionalItems) {
602602
functionCode += `
603603
for (let i = ${itemsSchema.length}; i < arrayLength; i++) {
604-
json += JSON.stringify(obj[i])
605-
if (i < arrayEnd) {
604+
if (i) {
606605
json += JSON_STR_COMMA
607606
}
607+
json += JSON.stringify(obj[i])
608608
}`
609609
}
610610
} else {
611611
const code = buildValue(context, itemsLocation, 'value')
612612
functionCode += `
613613
for (let i = 0; i < arrayLength; i++) {
614-
const value = obj[i]
615-
${code}
616-
if (i < arrayEnd) {
614+
if (i) {
617615
json += JSON_STR_COMMA
618616
}
617+
const value = obj[i]
618+
${code}
619619
}`
620620
}
621621

0 commit comments

Comments
 (0)