mirror of
https://github.com/nodejs/node.git
synced 2026-11-27 17:52:27 -05:00
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: https://github.com/nodejs/node/pull/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>
This commit is contained in:
1 parent
bfabfb4d17
commit
0d70c79ebf
1 file changed
+2
-6
@@ -6,9 +6,9 @@ const {
|
||||
Error,
|
||||
ErrorCaptureStackTrace,
|
||||
MathMax,
|
||||
ObjectAssign,
|
||||
ObjectDefineProperty,
|
||||
ObjectGetPrototypeOf,
|
||||
ObjectKeys,
|
||||
String,
|
||||
StringPrototypeEndsWith,
|
||||
StringPrototypeRepeat,
|
||||
@@ -46,11 +46,7 @@ const kReadableOperator = {
|
||||
const kMaxShortLength = 12;
|
||||
|
||||
function copyError(source) {
|
||||
const keys = ObjectKeys(source);
|
||||
const target = { __proto__: ObjectGetPrototypeOf(source) };
|
||||
for (const key of keys) {
|
||||
target[key] = source[key];
|
||||
}
|
||||
const target = ObjectAssign({ __proto__: ObjectGetPrototypeOf(source) }, source);
|
||||
ObjectDefineProperty(target, 'message', { __proto__: null, value: source.message });
|
||||
return target;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user