-
Notifications
You must be signed in to change notification settings - Fork 28.6k
Added identical(a,b) short circuit to painting Library lerp methods #121346
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added identical(a,b) short circuit to painting Library lerp methods #121346
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
expect(EdgeInsets.lerp(null, null, 0), null); | ||
const EdgeInsets insets = EdgeInsets.zero; | ||
expect(identical(EdgeInsets.lerp(insets, insets, 0.5), insets), true); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: remove blank line here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
796704b
to
655918e
Compare
Handle a common case in Foo.lerp(a, b, t): if a and b are identical, then just return a. This avoids needlessly constructing a new Foo and recursively lerping all of its properties. If a and b refer to the same const object, then we also preserve their singleton identity.
This PR is similar to #120829
Nearly all of the lerp methods in the painting library began with:
This PR safely generalizes the short-circuit to:
There were a few lerp methods that did not follow this pattern.
lerp(null, null, t)
and so theidentical
seems to only be an improvement.