-
Notifications
You must be signed in to change notification settings - Fork 26.7k
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
custom hashCode/== in Element to speed up inheritFromWidgetOfExactType #13019
Conversation
// Custom implementation of `operator ==` optimized for the ".of" pattern | ||
// used with `InheritedWidgets`. | ||
@override | ||
bool operator ==(Object other) => identical(this, other); |
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.
is that not what the inherited operator == does?
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.
I believe so, but the linter says if you overload hashCode
you must also overload operator==
.
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.
fair enough. i guess this is no worse than an // ignore
would be.
// `Set` look-ups, putting this getter on the performance critical path. | ||
@override | ||
int get hashCode => _cachedHash; | ||
final int _cachedHash = _nextHashCode = (_nextHashCode + 1) % 0xffffff; |
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.
why only 24 bits?
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.
Copied from dart-lang/sdk#31011 (comment), but I'm guessing this is so it fits within the SMI representation.
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.
Adding a comment with explanation.
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.
We're about to switch to 64bit ints, which might make this moot.
cc @floitschG for advice.
flutter#13019) * custom hashCode/== in Element to speed up inheritFromWidgetOfExactType * explain why 24 bits
See dart-lang/sdk#31011
WARNING: There's an ongoing regression introduced by #12933