Skip to content

Commit

Permalink
Optimize previous style calculation in styleUpdater (#3950)
Browse files Browse the repository at this point in the history
## Summary

This PR contains two little optimizations in `styleUpdater`:

1. Since we never use `oldValues` again (because references the same
object as `state.last` does before we overwrite it in the very same
line), we can re-use this instance instead of creating a new one.
2. Since we just calculated the difference between the new and old
styles, we can overwrite `oldValues` just with `diff` instead of
`newValues` because the values that are not present in `diff` are the
same in `oldValues` and `newValues`.

Co-authored-by: @kmagiera

## Test plan

Just check if BokehExample works.
  • Loading branch information
tomekzaw authored Jan 17, 2023
1 parent 93afccf commit a7c3834
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/reanimated2/hook/useAnimatedStyle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ function styleUpdater(
requestAnimationFrame(frame);
}
}
state.last = Object.assign({}, oldValues, newValues);
state.last = Object.assign(oldValues, newValues);
const style = getStyleWithoutAnimations(state.last);
if (style) {
updateProps(viewDescriptors, style, maybeViewRef);
Expand All @@ -254,7 +254,7 @@ function styleUpdater(
state.animations = [];

const diff = styleDiff(oldValues, newValues);
state.last = Object.assign({}, oldValues, newValues);
state.last = Object.assign(oldValues, diff);
if (diff) {
updateProps(viewDescriptors, newValues, maybeViewRef);
}
Expand Down Expand Up @@ -353,7 +353,7 @@ function jestStyleUpdater(

// calculate diff
const diff = styleDiff(oldValues, newValues);
state.last = Object.assign({}, oldValues, newValues);
state.last = Object.assign(oldValues, diff);

if (Object.keys(diff).length !== 0) {
updatePropsJestWrapper(
Expand Down

0 comments on commit a7c3834

Please sign in to comment.