Skip to content

Commit

Permalink
Preallocate arrays when generating fromObject methods
Browse files Browse the repository at this point in the history
  • Loading branch information
adriancable committed Sep 24, 2024
1 parent 19e1fef commit 0fbf200
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/converter.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ converter.fromObject = function fromObject(mtype) {
("if(d%s){", prop)
("if(!Array.isArray(d%s))", prop)
("throw TypeError(%j)", field.fullName + ": array expected")
("m%s=[]", prop)
("m%s=Array(d%s.length)", prop, prop)
("for(var i=0;i<d%s.length;++i){", prop);
genValuePartial_fromObject(gen, field, /* not sorted */ i, prop + "[i]")
("}")
Expand Down Expand Up @@ -281,7 +281,7 @@ converter.toObject = function toObject(mtype) {
("}");
} else if (field.repeated) { gen
("if(m%s&&m%s.length){", prop, prop)
("d%s=[]", prop)
("d%s=Array(m%s.length)", prop, prop)
("for(var j=0;j<m%s.length;++j){", prop);
genValuePartial_toObject(gen, field, /* sorted */ index, prop + "[j]")
("}");
Expand Down

0 comments on commit 0fbf200

Please sign in to comment.