Skip to content

Utilize new Object.hash function instead of quiver code #2868

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

Merged
merged 3 commits into from
Dec 30, 2021
Merged
Show file tree
Hide file tree
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
3 changes: 1 addition & 2 deletions lib/src/matching_link_result.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import 'package:dartdoc/src/model/comment_referable.dart';
import 'package:dartdoc/src/model/model.dart';
import 'package:dartdoc/src/quiver.dart';

class MatchingLinkResult {
final CommentReferable? commentReferable;
Expand All @@ -20,7 +19,7 @@ class MatchingLinkResult {
}

@override
int get hashCode => hash2(commentReferable, warn);
int get hashCode => Object.hash(commentReferable, warn);

@override
String toString() {
Expand Down
29 changes: 0 additions & 29 deletions lib/src/quiver.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,32 +11,3 @@
/// The returned iterable is a lazily-evaluated view on the input iterables.
Iterable<T> concat<T>(Iterable<Iterable<T>> iterables) =>
iterables.expand((x) => x);

// From lib/src/core/hash.dart:

/// Generates a hash code for two objects.
int hash2(Object? a, Object? b) =>
_finish(_combine(_combine(0, a.hashCode), b.hashCode));

/// Generates a hash code for three objects.
int hash3(Object? a, Object? b, Object? c) => _finish(
_combine(_combine(_combine(0, a.hashCode), b.hashCode), c.hashCode));

/// Generates a hash code for four objects.
int hash4(Object? a, Object? b, Object? c, Object? d) => _finish(_combine(
_combine(_combine(_combine(0, a.hashCode), b.hashCode), c.hashCode),
d.hashCode));

// Jenkins hash functions

int _combine(int hash, int value) {
hash = 0x1fffffff & (hash + value);
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));
}
10 changes: 3 additions & 7 deletions lib/src/tuple.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
// file for details. All rights reserved. Use of this source code is governed
// by a BSD-style license that can be found in the LICENSE file.

import 'package:dartdoc/src/quiver.dart' as quiver;

/// Represents a 2-tuple, or pair.
class Tuple2<T1, T2> {
/// Returns the first item of the tuple
Expand All @@ -26,7 +24,7 @@ class Tuple2<T1, T2> {
other is Tuple2 && other.item1 == item1 && other.item2 == item2;

@override
int get hashCode => quiver.hash2(item1.hashCode, item2.hashCode);
int get hashCode => Object.hash(item1, item2);
}

/// Represents a 3-tuple, or triple.
Expand Down Expand Up @@ -54,8 +52,7 @@ class Tuple3<T1, T2, T3> {
other.item3 == item3;

@override
int get hashCode =>
quiver.hash3(item1.hashCode, item2.hashCode, item3.hashCode);
int get hashCode => Object.hash(item1, item2, item3);
}

/// Represents a 4-tuple, or quadruple.
Expand Down Expand Up @@ -87,6 +84,5 @@ class Tuple4<T1, T2, T3, T4> {
other.item4 == item4;

@override
int get hashCode => quiver.hash4(
item1.hashCode, item2.hashCode, item3.hashCode, item4.hashCode);
int get hashCode => Object.hash(item1, item2, item3, item4);
}
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version: 4.1.0
description: A non-interactive HTML documentation generator for Dart source code.
homepage: https://github.com/dart-lang/dartdoc
environment:
sdk: '>=2.12.0 <3.0.0'
sdk: '>=2.14.0 <3.0.0'

dependencies:
analyzer: ^2.7.0
Expand Down
17 changes: 0 additions & 17 deletions test/quiver_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,21 +54,4 @@ void main() {
expect(ab, [1, 2, 3, 4, 5, 6]);
});
});

group('hash', () {
test('hash2 should return an int', () {
var h = hash2('123', 456);
expect(h, isA<int>());
});

test('hash3 should return an int', () {
var h = hash3('123', 456, true);
expect(h, isA<int>());
});

test('hash4 should return an int', () {
var h = hash4('123', 456, true, []);
expect(h, isA<int>());
});
});
}