Skip to content

Commit d19cece

Browse files
authored
perf(utils): optimized reducer to avoid creating new objects (#8818)
1 parent ede1f39 commit d19cece

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

packages/vitest/src/utils/serialization.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
function cloneByOwnProperties(value: any) {
44
// Clones the value's properties into a new Object. The simpler approach of
55
// Object.assign() won't work in the case that properties are not enumerable.
6-
return Object.getOwnPropertyNames(value).reduce(
7-
(clone, prop) => ({
8-
...clone,
9-
[prop]: value[prop],
10-
}),
6+
return Object.getOwnPropertyNames(value).reduce<Record<string, any>>(
7+
(clone, prop) => {
8+
clone[prop] = value[prop]
9+
return clone
10+
},
1111
{},
1212
)
1313
}

0 commit comments

Comments
 (0)