Skip to content

Commit 67567b9

Browse files
committed
Look up Object.prototype.hasOwnProperty once and wrap call in helper function
1 parent 95c011a commit 67567b9

File tree

4 files changed

+19
-10
lines changed

4 files changed

+19
-10
lines changed

dist/fast-json-patch.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,11 @@ var __extends = (this && this.__extends) || function (d, b) {
8282
* (c) 2017 Joachim Wester
8383
* MIT license
8484
*/
85+
var _hasOwnProperty = Object.prototype.hasOwnProperty;
86+
function hasOwnProperty(obj, key) {
87+
return _hasOwnProperty.call(obj, key);
88+
}
89+
exports.hasOwnProperty = hasOwnProperty;
8590
function _objectKeys(obj) {
8691
if (Array.isArray(obj)) {
8792
var keys = new Array(obj.length);
@@ -95,7 +100,7 @@ function _objectKeys(obj) {
95100
}
96101
var keys = [];
97102
for (var i in obj) {
98-
if (Object.prototype.hasOwnProperty.call(obj, i)) {
103+
if (hasOwnProperty(obj, i)) {
99104
keys.push(i);
100105
}
101106
}
@@ -159,7 +164,7 @@ exports.unescapePathComponent = unescapePathComponent;
159164
function _getPathRecursive(root, obj) {
160165
var found;
161166
for (var key in root) {
162-
if (Object.prototype.hasOwnProperty.call(root, key)) {
167+
if (hasOwnProperty(root, key)) {
163168
if (root[key] === obj) {
164169
return escapePathComponent(key) + '/';
165170
}
@@ -876,7 +881,7 @@ function _generate(mirror, obj, patches, path) {
876881
for (var t = oldKeys.length - 1; t >= 0; t--) {
877882
var key = oldKeys[t];
878883
var oldVal = mirror[key];
879-
if (Object.prototype.hasOwnProperty.call(obj, key) && !(obj[key] === undefined && oldVal !== undefined && Array.isArray(obj) === false)) {
884+
if (helpers_1.hasOwnProperty(obj, key) && !(obj[key] === undefined && oldVal !== undefined && Array.isArray(obj) === false)) {
880885
var newVal = obj[key];
881886
if (typeof oldVal == "object" && oldVal != null && typeof newVal == "object" && newVal != null) {
882887
_generate(oldVal, newVal, patches, path + "/" + helpers_1.escapePathComponent(key));
@@ -898,7 +903,7 @@ function _generate(mirror, obj, patches, path) {
898903
}
899904
for (var t = 0; t < newKeys.length; t++) {
900905
var key = newKeys[t];
901-
if (!Object.prototype.hasOwnProperty.call(mirror, key) && obj[key] !== undefined) {
906+
if (!helpers_1.hasOwnProperty(mirror, key) && obj[key] !== undefined) {
902907
patches.push({ op: "add", path: path + "/" + helpers_1.escapePathComponent(key), value: helpers_1._deepClone(obj[key]) });
903908
}
904909
}

0 commit comments

Comments
 (0)