Skip to content

Commit

Permalink
Avoids unnecessary copy of patches in applyPatches
Browse files Browse the repository at this point in the history
  • Loading branch information
Louis DeScioli committed Nov 18, 2021
1 parent abba680 commit fe80e02
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/core/immerClass.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,11 @@ export class Immer implements ProducersFns {
break
}
}
// If there was a patch that replaced the entire state, start from the
// patch after that.
if (i > -1) {
patches = patches.slice(i + 1)
}

const applyPatchesImpl = getPlugin("Patches").applyPatches_
if (isDraft(base)) {
Expand All @@ -204,7 +209,7 @@ export class Immer implements ProducersFns {
}
// Otherwise, produce a copy of the base state.
return this.produce(base, (draft: Drafted) =>
applyPatchesImpl(draft, patches.slice(i + 1))
applyPatchesImpl(draft, patches)
)
}
}
Expand Down

0 comments on commit fe80e02

Please sign in to comment.