Skip to content

BuiltList won't compute hash as part of ==. #269

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions lib/src/list/built_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,7 @@ abstract class BuiltList<E> implements Iterable<E>, BuiltIterable<E> {
/// A `BuiltList` is only equal to another `BuiltList` with equal elements in
/// the same order. Then, the `hashCode` is guaranteed to be the same.
@override
int get hashCode {
_hashCode ??= hashObjects(_list);
return _hashCode!;
}
int get hashCode => _hashCode ??= hashObjects(_list);

/// Deep equality.
///
Expand All @@ -79,7 +76,11 @@ abstract class BuiltList<E> implements Iterable<E>, BuiltIterable<E> {
if (identical(other, this)) return true;
if (other is! BuiltList) return false;
if (other.length != length) return false;
if (other.hashCode != hashCode) return false;
if (_hashCode != null &&
other._hashCode != null &&
_hashCode != other._hashCode) {
return false;
}
for (var i = 0; i != length; ++i) {
if (other[i] != this[i]) return false;
Copy link
Author

@lrhn lrhn Jan 3, 2023

Choose a reason for hiding this comment

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

For curiosity: This is the opposite order of what the platform collections otherwise use. For example. contains will use this[i] == needle as a test, not the other way around.
Is there a reason this is not this[i] == other[i]?

Copy link
Contributor

Choose a reason for hiding this comment

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

No reason that I can remember :)

}
Expand Down