Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 4c855be

Browse files
SheneekaWmattphillips
SheneekaW
authored andcommitted
remove spread operator in object diffs to increase performance
1 parent 8c09976 commit 4c855be

File tree

4 files changed

+22
-8
lines changed

4 files changed

+22
-8
lines changed

‎src/added.js‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@ const addedDiff = (lhs, rhs) => {
1313

1414
if (isObject(difference) && isEmpty(difference)) return acc;
1515

16-
return { ...acc, [key]: difference };
16+
acc[key] = difference;
17+
return acc;
1718
}
1819

19-
return { ...acc, [key]: r[key] };
20+
acc[key] = r[key];
21+
return acc;
2022
}, {});
2123
};
2224

‎src/deleted.js‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,12 @@ const deletedDiff = (lhs, rhs) => {
1212

1313
if (isObject(difference) && isEmpty(difference)) return acc;
1414

15-
return { ...acc, [key]: difference };
15+
acc[key] = difference;
16+
return acc;
1617
}
1718

18-
return { ...acc, [key]: undefined };
19+
acc[key] = undefined;
20+
return acc;
1921
}, {});
2022
};
2123

‎src/diff.js‎

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,12 @@ const diff = (lhs, rhs) => {
99
const r = rhs;
1010

1111
const deletedValues = Object.keys(l).reduce((acc, key) => {
12-
return hasOwnProperty(r, key) ? acc : { ...acc, [key]: undefined };
12+
if (!hasOwnProperty(r, key)) {
13+
acc[key] = undefined;
14+
15+
}
16+
17+
return acc;
1318
}, {});
1419

1520
if (isDate(l) || isDate(r)) {
@@ -18,15 +23,19 @@ const diff = (lhs, rhs) => {
1823
}
1924

2025
return Object.keys(r).reduce((acc, key) => {
21-
if (!hasOwnProperty(l, key)) return { ...acc, [key]: r[key] }; // return added r key
26+
if (!hasOwnProperty(l, key)){
27+
acc[key] = r[key]; // return added r key
28+
return acc;
29+
}
2230

2331
const difference = diff(l[key], r[key]);
2432

2533
// If the difference is empty, and the lhs is an empty object or the rhs is not an empty object
2634
if (isEmptyObject(difference) && !isDate(difference) && (isEmptyObject(l[key]) || !isEmptyObject(r[key])))
2735
return acc; // return no diff
2836

29-
return { ...acc, [key]: difference }; // return updated key
37+
acc[key] = difference // return updated key
38+
return acc; // return updated key
3039
}, deletedValues);
3140
};
3241

‎src/updated.js‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ const updatedDiff = (lhs, rhs) => {
2121
if (isEmptyObject(difference) && !isDate(difference) && (isEmptyObject(l[key]) || !isEmptyObject(r[key])))
2222
return acc; // return no diff
2323

24-
return { ...acc, [key]: difference };
24+
acc[key] = difference;
25+
return acc;
2526
}
2627

2728
return acc;

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /