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

Appearance settings

Commit 0d70c79

Browse filesBrowse files
rayark1marco-ippolito
authored andcommitted
lib: optimize copyError with ObjectAssign in primordials
optimized the copyError function by using ObjectAssign from primordials. this change replaces the for-loop with ObjectAssign, which improves memory usage and performance. this change updates the copyError function in internal/assert.js to use ObjectAssign for copying properties. PR-URL: #53999 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Daeyeon Jeong <daeyeon.dev@gmail.com>
1 parent bfabfb4 commit 0d70c79
Copy full SHA for 0d70c79

1 file changed

+2-6Lines changed: 2 additions & 6 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎lib/internal/assert/assertion_error.js‎

Copy file name to clipboardExpand all lines: lib/internal/assert/assertion_error.js
+2-6Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ const {
66
Error,
77
ErrorCaptureStackTrace,
88
MathMax,
9+
ObjectAssign,
910
ObjectDefineProperty,
1011
ObjectGetPrototypeOf,
11-
ObjectKeys,
1212
String,
1313
StringPrototypeEndsWith,
1414
StringPrototypeRepeat,
@@ -46,11 +46,7 @@ const kReadableOperator = {
4646
const kMaxShortLength = 12;
4747

4848
function copyError(source) {
49-
const keys = ObjectKeys(source);
50-
const target = { __proto__: ObjectGetPrototypeOf(source) };
51-
for (const key of keys) {
52-
target[key] = source[key];
53-
}
49+
const target = ObjectAssign({ __proto__: ObjectGetPrototypeOf(source) }, source);
5450
ObjectDefineProperty(target, 'message', { __proto__: null, value: source.message });
5551
return target;
5652
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.