Skip to content

Commit 5567a2f

Browse files
perf(json-utils): iterate patch keys without Object.keys allocation (#362)
Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
1 parent 72f8217 commit 5567a2f

1 file changed

Lines changed: 8 additions & 6 deletions

File tree

src/core/json-utils.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,14 @@ export function applyMergePatch(target: unknown, patch: unknown, depth = 0): unk
9494
}
9595

9696
const patchObj = patch as Record<string, unknown>;
97-
for (const key of Object.keys(patchObj)) {
98-
const val = patchObj[key];
99-
if (val === null) {
100-
delete targetObj[key];
101-
} else {
102-
targetObj[key] = applyMergePatch(targetObj[key], val, depth + 1);
97+
for (const key in patchObj) {
98+
if (Object.prototype.hasOwnProperty.call(patchObj, key)) {
99+
const val = patchObj[key];
100+
if (val === null) {
101+
delete targetObj[key];
102+
} else {
103+
targetObj[key] = applyMergePatch(targetObj[key], val, depth + 1);
104+
}
103105
}
104106
}
105107

0 commit comments

Comments
 (0)