Skip to content

Commit

Permalink
faster unstrict mode
Browse files Browse the repository at this point in the history
  • Loading branch information
mweststrate committed Mar 11, 2024
1 parent 8e465ab commit 744d2d9
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/utils/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,13 @@ export function shallowCopy(base: any, strict: boolean) {
}
if (Array.isArray(base)) return Array.prototype.slice.call(base)

if (!strict && isPlainObject(base)) {
if (!getPrototypeOf(base)) {
const obj = Object.create(null)
return Object.assign(obj, base)
if (!strict) {
const proto = getPrototypeOf(base)
if (proto !== null && isPlainObject(base)) {
return {...base} // assumption: better inner class optimization than the assign below
}
return {...base}
const obj = Object.create(proto)
return Object.assign(obj, base)
}

const descriptors = Object.getOwnPropertyDescriptors(base)
Expand Down

0 comments on commit 744d2d9

Please sign in to comment.