Permalink
Browse files

Other: Call hasOwnProperty builtin as late as possible decreasing the…

… probability of having to call it at all (perf)
  • Loading branch information...
dcodeIO committed Jan 16, 2017
1 parent 818bcac commit 2c94b641fc5700c8781ac0b9fe796debac8d6893

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

Large diffs are not rendered by default.

Oops, something went wrong.

Large diffs are not rendered by default.

Oops, something went wrong.
BIN +2 Bytes (100%) dist/noparse/protobuf.min.js.gz
Binary file not shown.

Large diffs are not rendered by default.

Oops, something went wrong.

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

Large diffs are not rendered by default.

Oops, something went wrong.

Large diffs are not rendered by default.

Oops, something went wrong.
BIN +2 Bytes (100%) dist/protobuf.min.js.gz
Binary file not shown.

Large diffs are not rendered by default.

Oops, something went wrong.

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

Large diffs are not rendered by default.

Oops, something went wrong.

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
BIN +0 Bytes (100%) dist/runtime/protobuf.min.js.gz
Binary file not shown.

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -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",
@@ -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);
@@ -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
@@ -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)
@@ -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]");
@@ -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);
}
@@ -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++]);
@@ -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",

0 comments on commit 2c94b64

Please sign in to comment.