Skip to content

Commit

Permalink
Other: Call hasOwnProperty builtin as late as possible decreasing the…
Browse files Browse the repository at this point in the history
… probability of having to call it at all (perf)
  • Loading branch information
dcodeIO committed Jan 16, 2017
1 parent 818bcac commit 2c94b64
Show file tree
Hide file tree
Showing 20 changed files with 47 additions and 44 deletions.
19 changes: 10 additions & 9 deletions dist/noparse/protobuf.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/noparse/protobuf.js.map

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions dist/noparse/protobuf.min.js

Large diffs are not rendered by default.

Binary file modified dist/noparse/protobuf.min.js.gz
Binary file not shown.
2 changes: 1 addition & 1 deletion dist/noparse/protobuf.min.js.map

Large diffs are not rendered by default.

19 changes: 10 additions & 9 deletions dist/protobuf.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/protobuf.js.map

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions dist/protobuf.min.js

Large diffs are not rendered by default.

Binary file modified dist/protobuf.min.js.gz
Binary file not shown.
2 changes: 1 addition & 1 deletion dist/protobuf.min.js.map

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions dist/runtime/protobuf.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/runtime/protobuf.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/runtime/protobuf.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified dist/runtime/protobuf.min.js.gz
Binary file not shown.
2 changes: 1 addition & 1 deletion dist/runtime/protobuf.min.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"dependencies": {
"@protobufjs/aspromise": "^1.0.5",
"@protobufjs/base64": "^1.0.5",
"@protobufjs/codegen": "^1.0.7",
"@protobufjs/codegen": "^1.0.8",
"@protobufjs/eventemitter": "^1.0.5",
"@protobufjs/extend": "^1.0.2",
"@protobufjs/fetch": "^1.0.4",
Expand Down
2 changes: 1 addition & 1 deletion src/converter.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ converter.toObject = function toObject(mtype) {
for (var i = 0; i < fields.length; ++i) {
var field = fields[i],
prop = util.safeProp(field.name); gen
("if(m.hasOwnProperty(%j)&&m%s!==undefined&&m%s!==null){", field.name, prop, prop);
("if(m%s!==undefined&&m%s!==null&&m.hasOwnProperty(%j)){", prop, prop, field.name);
if (field.map) { gen
("d%s={}", prop)
("for(var ks2=Object.keys(m%s),j=0;j<ks2.length;++j){", prop);
Expand Down
12 changes: 6 additions & 6 deletions src/encoder.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ function encoder(mtype) {
// Map fields
if (field.map) {
var keyType = field.resolvedKeyType /* only valid is enum */ ? "uint32" : field.keyType; gen
("if(m.hasOwnProperty(%j)&&%s){", field.name, ref)
("if(%s&&m.hasOwnProperty(%j)){", ref, field.name)
("for(var ks=Object.keys(%s),i=0;i<ks.length;++i){", ref)
("w.uint32(%d).fork().uint32(%d).%s(ks[i])", (field.id << 3 | 2) >>> 0, 8 | types.mapKey[keyType], keyType);
if (wireType === undefined) gen
Expand All @@ -62,7 +62,7 @@ function encoder(mtype) {
// Packed repeated
if (field.packed && types.packed[type] !== undefined) { gen

("if(m.hasOwnProperty(%j)&&%s.length){", field.name, ref)
("if(%s&&%s.length&&m.hasOwnProperty(%j)){", ref, ref, field.name)
("w.uint32(%d).fork()", (field.id << 3 | 2) >>> 0)
("for(var i=0;i<%s.length;++i)", ref)
("w.%s(%s[i])", type, ref)
Expand All @@ -72,7 +72,7 @@ function encoder(mtype) {
// Non-packed
} else { gen

("if(m.hasOwnProperty(%j)){", field.name)
("if(%s!==undefined&&m.hasOwnProperty(%j)){", ref, field.name)
("for(var i=0;i<%s.length;++i)", ref);
if (wireType === undefined)
genTypePartial(gen, field, i, ref + "[i]");
Expand All @@ -88,11 +88,11 @@ function encoder(mtype) {
if (!field.required) {

if (field.long) gen
("if(m.hasOwnProperty(%j)&&%s!==undefined&&%s!==null)", field.name, ref, ref);
("if(%s!==undefined&&%s!==null&&m.hasOwnProperty(%j))", ref, ref, field.name);
else if (field.bytes) gen
("if(m.hasOwnProperty(%j)&&%s)", field.name, ref);
("if(%s&&m.hasOwnProperty(%j))", ref, field.name);
else gen
("if(m.hasOwnProperty(%j)&&%s!==undefined)", field.name, ref);
("if(%s!==undefined&&m.hasOwnProperty(%j))", ref, field.name);

}

Expand Down
2 changes: 1 addition & 1 deletion src/util/codegen/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ function sprintf(format) {
for (; i < arguments.length;)
args.push(arguments[i++]);
i = 0;
format = format.replace(/%([dfjps])/g, function($0, $1) {
format = format.replace(/%([dfjs])/g, function($0, $1) {
switch ($1) {
case "d":
return Math.floor(args[i++]);
Expand Down
2 changes: 1 addition & 1 deletion src/util/codegen/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@protobufjs/codegen",
"description": "A closure for generating functions programmatically.",
"version": "1.0.7",
"version": "1.0.8",
"author": "Daniel Wirtz <dcode+protobufjs@dcode.io>",
"repository": {
"type": "git",
Expand Down

0 comments on commit 2c94b64

Please sign in to comment.