Skip to content
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

Merged
merged 2 commits into from Nov 15, 2017

Conversation

yjbanov
Copy link
Contributor

@yjbanov yjbanov commented Nov 14, 2017

See dart-lang/sdk#31011
WARNING: There's an ongoing regression introduced by #12933

// Custom implementation of `operator ==` optimized for the ".of" pattern
// used with `InheritedWidgets`.
@override
bool operator ==(Object other) => identical(this, other);
Copy link
Contributor

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?

Copy link
Contributor Author

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==.

Copy link
Contributor

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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why only 24 bits?

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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.

@Hixie
Copy link
Contributor

Hixie commented Nov 15, 2017

LGTM

@yjbanov yjbanov merged commit 6be0846 into flutter:master Nov 15, 2017
DaveShuckerow pushed a commit to DaveShuckerow/flutter that referenced this pull request May 14, 2018
flutter#13019)

* custom hashCode/== in Element to speed up inheritFromWidgetOfExactType

* explain why 24 bits
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 12, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants