Make final parameter of SystemHash.hashX not be optional.

Issue https://github.com/dart-lang/sdk/issues/50693

Change-Id: Ib587b70bcb57cbd2d16319b7814e2569c7e41213
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/276161
Commit-Queue: Lasse Nielsen <lrn@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
This commit is contained in:
Lasse R.H. Nielsen 2023-01-02 12:44:23 +00:00 committed by Commit Queue
parent 628dd02bc8
commit ece7da8009
5 changed files with 52 additions and 60 deletions

View file

@ -28,7 +28,7 @@ abstract class Node5 {
class Node5Hash extends Node5 {
// This is the main subject of the benchmark - a typical use of `Object.hash`.
@override
int get hashCode => Object.hash(item1, item2, item3, item4, item5);
int get hashCode => Object.hash(item1, item2, item3, item4, item5, 0);
}
class Node5Manual extends Node5 {
@ -36,7 +36,7 @@ class Node5Manual extends Node5 {
// `hashCode` calls.
@override
int get hashCode => _SystemHash.hash5(item1.hashCode, item2.hashCode,
item3.hashCode, item4.hashCode, item5.hashCode);
item3.hashCode, item4.hashCode, item5.hashCode, 0);
}
class Node5List extends Node5 {
@ -190,10 +190,11 @@ void generalUses() {
check(Object.hash(a6, a7, a1, a2, a3), Object.hash(a6, a7, a1, a2, a3));
check(Object.hash(a7, a1, a2, a3, a4), Object.hash(a7, a1, a2, a3, a4));
check(_SystemHash.hash2(1, 2), _SystemHash.hash2(1, 2));
check(_SystemHash.hash3(1, 2, 3), _SystemHash.hash3(1, 2, 3));
check(_SystemHash.hash4(1, 2, 3, 4), _SystemHash.hash4(1, 2, 3, 4));
check(_SystemHash.hash5(1, 2, 3, 4, 5), _SystemHash.hash5(1, 2, 3, 4, 5));
check(_SystemHash.hash2(1, 2, 0), _SystemHash.hash2(1, 2, 0));
check(_SystemHash.hash3(1, 2, 3, 0), _SystemHash.hash3(1, 2, 3, 0));
check(_SystemHash.hash4(1, 2, 3, 4, 0), _SystemHash.hash4(1, 2, 3, 4, 0));
check(
_SystemHash.hash5(1, 2, 3, 4, 5, 0), _SystemHash.hash5(1, 2, 3, 4, 5, 0));
// Pollute hashAll argument type.
check(Object.hashAll({}), Object.hashAll([]));
@ -217,14 +218,14 @@ class _SystemHash {
return 0x1fffffff & (hash + ((0x00003fff & hash) << 15));
}
static int hash2(int v1, int v2, [int seed = 0]) {
static int hash2(int v1, int v2, int seed) {
int hash = seed;
hash = combine(hash, v1);
hash = combine(hash, v2);
return finish(hash);
}
static int hash3(int v1, int v2, int v3, [int seed = 0]) {
static int hash3(int v1, int v2, int v3, int seed) {
int hash = seed;
hash = combine(hash, v1);
hash = combine(hash, v2);
@ -232,7 +233,7 @@ class _SystemHash {
return finish(hash);
}
static int hash4(int v1, int v2, int v3, int v4, [int seed = 0]) {
static int hash4(int v1, int v2, int v3, int v4, int seed) {
int hash = seed;
hash = combine(hash, v1);
hash = combine(hash, v2);
@ -241,7 +242,7 @@ class _SystemHash {
return finish(hash);
}
static int hash5(int v1, int v2, int v3, int v4, int v5, [int seed = 0]) {
static int hash5(int v1, int v2, int v3, int v4, int v5, int seed) {
int hash = seed;
hash = combine(hash, v1);
hash = combine(hash, v2);

View file

@ -556,7 +556,7 @@ class Object {
sum = (sum + objectHash) & mask;
count += 1;
}
return SystemHash.hash2(sum, count);
return SystemHash.hash2(sum, count, 0);
}
}

View file

@ -178,7 +178,6 @@ final Future<Null> nullFuture = Zone.root.run(() => Future<Null>.value(null));
///
/// TODO(lrn): Consider specializing this code per platform,
/// so the VM can use its 64-bit integers directly.
@Since("2.11")
class SystemHash {
static int combine(int hash, int value) {
hash = 0x1fffffff & (hash + value);
@ -192,14 +191,14 @@ class SystemHash {
return 0x1fffffff & (hash + ((0x00003fff & hash) << 15));
}
static int hash2(int v1, int v2, [@Since("2.14") int seed = 0]) {
static int hash2(int v1, int v2, int seed) {
int hash = seed;
hash = combine(hash, v1);
hash = combine(hash, v2);
return finish(hash);
}
static int hash3(int v1, int v2, int v3, [@Since("2.14") int seed = 0]) {
static int hash3(int v1, int v2, int v3, int seed) {
int hash = seed;
hash = combine(hash, v1);
hash = combine(hash, v2);
@ -207,8 +206,7 @@ class SystemHash {
return finish(hash);
}
static int hash4(int v1, int v2, int v3, int v4,
[@Since("2.14") int seed = 0]) {
static int hash4(int v1, int v2, int v3, int v4, int seed) {
int hash = seed;
hash = combine(hash, v1);
hash = combine(hash, v2);
@ -217,8 +215,7 @@ class SystemHash {
return finish(hash);
}
static int hash5(int v1, int v2, int v3, int v4, int v5,
[@Since("2.14") int seed = 0]) {
static int hash5(int v1, int v2, int v3, int v4, int v5, int seed) {
int hash = seed;
hash = combine(hash, v1);
hash = combine(hash, v2);
@ -228,8 +225,7 @@ class SystemHash {
return finish(hash);
}
static int hash6(int v1, int v2, int v3, int v4, int v5, int v6,
[@Since("2.14") int seed = 0]) {
static int hash6(int v1, int v2, int v3, int v4, int v5, int v6, int seed) {
int hash = seed;
hash = combine(hash, v1);
hash = combine(hash, v2);
@ -240,8 +236,8 @@ class SystemHash {
return finish(hash);
}
static int hash7(int v1, int v2, int v3, int v4, int v5, int v6, int v7,
[@Since("2.14") int seed = 0]) {
static int hash7(
int v1, int v2, int v3, int v4, int v5, int v6, int v7, int seed) {
int hash = seed;
hash = combine(hash, v1);
hash = combine(hash, v2);
@ -253,9 +249,8 @@ class SystemHash {
return finish(hash);
}
static int hash8(
int v1, int v2, int v3, int v4, int v5, int v6, int v7, int v8,
[@Since("2.14") int seed = 0]) {
static int hash8(int v1, int v2, int v3, int v4, int v5, int v6, int v7,
int v8, int seed) {
int hash = seed;
hash = combine(hash, v1);
hash = combine(hash, v2);
@ -268,9 +263,8 @@ class SystemHash {
return finish(hash);
}
static int hash9(
int v1, int v2, int v3, int v4, int v5, int v6, int v7, int v8, int v9,
[@Since("2.14") int seed = 0]) {
static int hash9(int v1, int v2, int v3, int v4, int v5, int v6, int v7,
int v8, int v9, int seed) {
int hash = seed;
hash = combine(hash, v1);
hash = combine(hash, v2);
@ -285,8 +279,7 @@ class SystemHash {
}
static int hash10(int v1, int v2, int v3, int v4, int v5, int v6, int v7,
int v8, int v9, int v10,
[@Since("2.14") int seed = 0]) {
int v8, int v9, int v10, int seed) {
int hash = seed;
hash = combine(hash, v1);
hash = combine(hash, v2);
@ -301,10 +294,8 @@ class SystemHash {
return finish(hash);
}
@Since("2.14")
static int hash11(int v1, int v2, int v3, int v4, int v5, int v6, int v7,
int v8, int v9, int v10, int v11,
[int seed = 0]) {
int v8, int v9, int v10, int v11, int seed) {
int hash = seed;
hash = combine(hash, v1);
hash = combine(hash, v2);
@ -320,10 +311,8 @@ class SystemHash {
return finish(hash);
}
@Since("2.14")
static int hash12(int v1, int v2, int v3, int v4, int v5, int v6, int v7,
int v8, int v9, int v10, int v11, int v12,
[int seed = 0]) {
int v8, int v9, int v10, int v11, int v12, int seed) {
int hash = seed;
hash = combine(hash, v1);
hash = combine(hash, v2);
@ -340,10 +329,8 @@ class SystemHash {
return finish(hash);
}
@Since("2.14")
static int hash13(int v1, int v2, int v3, int v4, int v5, int v6, int v7,
int v8, int v9, int v10, int v11, int v12, int v13,
[int seed = 0]) {
int v8, int v9, int v10, int v11, int v12, int v13, int seed) {
int hash = seed;
hash = combine(hash, v1);
hash = combine(hash, v2);
@ -361,10 +348,8 @@ class SystemHash {
return finish(hash);
}
@Since("2.14")
static int hash14(int v1, int v2, int v3, int v4, int v5, int v6, int v7,
int v8, int v9, int v10, int v11, int v12, int v13, int v14,
[int seed = 0]) {
int v8, int v9, int v10, int v11, int v12, int v13, int v14, int seed) {
int hash = seed;
hash = combine(hash, v1);
hash = combine(hash, v2);
@ -383,10 +368,23 @@ class SystemHash {
return finish(hash);
}
@Since("2.14")
static int hash15(int v1, int v2, int v3, int v4, int v5, int v6, int v7,
int v8, int v9, int v10, int v11, int v12, int v13, int v14, int v15,
[int seed = 0]) {
static int hash15(
int v1,
int v2,
int v3,
int v4,
int v5,
int v6,
int v7,
int v8,
int v9,
int v10,
int v11,
int v12,
int v13,
int v14,
int v15,
int seed) {
int hash = seed;
hash = combine(hash, v1);
hash = combine(hash, v2);
@ -406,7 +404,6 @@ class SystemHash {
return finish(hash);
}
@Since("2.14")
static int hash16(
int v1,
int v2,
@ -424,7 +421,7 @@ class SystemHash {
int v14,
int v15,
int v16,
[int seed = 0]) {
int seed) {
int hash = seed;
hash = combine(hash, v1);
hash = combine(hash, v2);
@ -445,7 +442,6 @@ class SystemHash {
return finish(hash);
}
@Since("2.14")
static int hash17(
int v1,
int v2,
@ -464,7 +460,7 @@ class SystemHash {
int v15,
int v16,
int v17,
[int seed = 0]) {
int seed) {
int hash = seed;
hash = combine(hash, v1);
hash = combine(hash, v2);
@ -486,7 +482,6 @@ class SystemHash {
return finish(hash);
}
@Since("2.14")
static int hash18(
int v1,
int v2,
@ -506,7 +501,7 @@ class SystemHash {
int v16,
int v17,
int v18,
[int seed = 0]) {
int seed) {
int hash = seed;
hash = combine(hash, v1);
hash = combine(hash, v2);
@ -529,7 +524,6 @@ class SystemHash {
return finish(hash);
}
@Since("2.14")
static int hash19(
int v1,
int v2,
@ -550,7 +544,7 @@ class SystemHash {
int v17,
int v18,
int v19,
[int seed = 0]) {
int seed) {
int hash = seed;
hash = combine(hash, v1);
hash = combine(hash, v2);
@ -574,7 +568,6 @@ class SystemHash {
return finish(hash);
}
@Since("2.14")
static int hash20(
int v1,
int v2,
@ -596,7 +589,7 @@ class SystemHash {
int v18,
int v19,
int v20,
[int seed = 0]) {
int seed) {
int hash = seed;
hash = combine(hash, v1);
hash = combine(hash, v2);
@ -644,14 +637,12 @@ class SystemHash {
}
/// Sentinel values that should never be exposed outside of platform libraries.
@Since("2.14")
class SentinelValue {
final int id;
const SentinelValue(this.id);
}
/// A default value to use when only one sentinel is needed.
@Since("2.14")
const Object sentinelValue = const SentinelValue(0);
/// Given an [instance] of some generic type [T], and [extract], a first-class

View file

@ -36,7 +36,7 @@ class Point<T extends num> {
bool operator ==(Object other) =>
other is Point && x == other.x && y == other.y;
int get hashCode => SystemHash.hash2(x.hashCode, y.hashCode);
int get hashCode => SystemHash.hash2(x.hashCode, y.hashCode, 0);
/// Add [other] to `this`, as if both points were vectors.
///

View file

@ -49,7 +49,7 @@ abstract class _RectangleBase<T extends num> {
bottom == other.bottom;
int get hashCode => SystemHash.hash4(
left.hashCode, top.hashCode, right.hashCode, bottom.hashCode);
left.hashCode, top.hashCode, right.hashCode, bottom.hashCode, 0);
/// Computes the intersection of `this` and [other].
///