Skip to content

Commit

Permalink
refactor: remove legacy equatable code
Browse files Browse the repository at this point in the history
  • Loading branch information
felangel committed Oct 16, 2024
1 parent 9daf628 commit 53a6930
Showing 1 changed file with 0 additions and 38 deletions.
38 changes: 0 additions & 38 deletions lib/src/_data_class.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,41 +6,3 @@ final dataClassMacro = Uri.parse('package:data_class/src/_data_class.dart');

// Methods used in augmented code.
const undefined = Object();
final deepEquals = const DeepCollectionEquality().equals;

// TODO(felangel): use jenkins hash from `package:equatable`
// once https://github.com/felangel/equatable/pull/174 is published.
/// Generate a hash for the provided [fields].
int hashAll(Iterable<Object?>? fields) {
return _finish(fields == null ? 0 : fields.fold(0, _combine));
}

int _combine(int hash, Object? object) {
if (object is Map) {
object.keys
.sorted((Object? a, Object? b) => a.hashCode - b.hashCode)
.forEach((Object? key) {
hash = hash ^ _combine(hash, [key, (object! as Map)[key]]);
});
return hash;
}
if (object is Set) {
object = object.sorted((Object? a, Object? b) => a.hashCode - b.hashCode);
}
if (object is Iterable) {
for (final value in object) {
hash = hash ^ _combine(hash, value);
}
return hash ^ object.length;
}

hash = 0x1fffffff & (hash + object.hashCode);
hash = 0x1fffffff & (hash + ((0x0007ffff & hash) << 10));
return hash ^ (hash >> 6);
}

int _finish(int hash) {
hash = 0x1fffffff & (hash + ((0x03ffffff & hash) << 3));
hash = hash ^ (hash >> 11);
return 0x1fffffff & (hash + ((0x00003fff & hash) << 15));
}

0 comments on commit 53a6930

Please sign in to comment.