Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit ad3db66

Browse files
author
auto-submit[bot]
committed
Revert "Drop deprecated hash_code functions (#54000)"
This reverts commit ea1e53a.
1 parent c2190d9 commit ad3db66

File tree

8 files changed

+413
-0
lines changed

8 files changed

+413
-0
lines changed

ci/licenses_golden/licenses_flutter

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42703,6 +42703,7 @@ ORIGIN: ../../../flutter/lib/ui/experiments/setup_hooks.dart + ../../../flutter/
4270342703
ORIGIN: ../../../flutter/lib/ui/experiments/ui.dart + ../../../flutter/LICENSE
4270442704
ORIGIN: ../../../flutter/lib/ui/floating_point.h + ../../../flutter/LICENSE
4270542705
ORIGIN: ../../../flutter/lib/ui/geometry.dart + ../../../flutter/LICENSE
42706+
ORIGIN: ../../../flutter/lib/ui/hash_codes.dart + ../../../flutter/LICENSE
4270642707
ORIGIN: ../../../flutter/lib/ui/hooks.dart + ../../../flutter/LICENSE
4270742708
ORIGIN: ../../../flutter/lib/ui/io_manager.cc + ../../../flutter/LICENSE
4270842709
ORIGIN: ../../../flutter/lib/ui/io_manager.h + ../../../flutter/LICENSE
@@ -42865,6 +42866,7 @@ ORIGIN: ../../../flutter/lib/web_ui/lib/canvas.dart + ../../../flutter/LICENSE
4286542866
ORIGIN: ../../../flutter/lib/web_ui/lib/channel_buffers.dart + ../../../flutter/LICENSE
4286642867
ORIGIN: ../../../flutter/lib/web_ui/lib/compositing.dart + ../../../flutter/LICENSE
4286742868
ORIGIN: ../../../flutter/lib/web_ui/lib/geometry.dart + ../../../flutter/LICENSE
42869+
ORIGIN: ../../../flutter/lib/web_ui/lib/hash_codes.dart + ../../../flutter/LICENSE
4286842870
ORIGIN: ../../../flutter/lib/web_ui/lib/initialization.dart + ../../../flutter/LICENSE
4286942871
ORIGIN: ../../../flutter/lib/web_ui/lib/key.dart + ../../../flutter/LICENSE
4287042872
ORIGIN: ../../../flutter/lib/web_ui/lib/lerp.dart + ../../../flutter/LICENSE
@@ -45581,6 +45583,7 @@ FILE: ../../../flutter/lib/ui/experiments/setup_hooks.dart
4558145583
FILE: ../../../flutter/lib/ui/experiments/ui.dart
4558245584
FILE: ../../../flutter/lib/ui/floating_point.h
4558345585
FILE: ../../../flutter/lib/ui/geometry.dart
45586+
FILE: ../../../flutter/lib/ui/hash_codes.dart
4558445587
FILE: ../../../flutter/lib/ui/hooks.dart
4558545588
FILE: ../../../flutter/lib/ui/io_manager.cc
4558645589
FILE: ../../../flutter/lib/ui/io_manager.h
@@ -45744,6 +45747,7 @@ FILE: ../../../flutter/lib/web_ui/lib/canvas.dart
4574445747
FILE: ../../../flutter/lib/web_ui/lib/channel_buffers.dart
4574545748
FILE: ../../../flutter/lib/web_ui/lib/compositing.dart
4574645749
FILE: ../../../flutter/lib/web_ui/lib/geometry.dart
45750+
FILE: ../../../flutter/lib/web_ui/lib/hash_codes.dart
4574745751
FILE: ../../../flutter/lib/web_ui/lib/initialization.dart
4574845752
FILE: ../../../flutter/lib/web_ui/lib/key.dart
4574945753
FILE: ../../../flutter/lib/web_ui/lib/lerp.dart

lib/ui/dart_ui.gni

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ dart_ui_files = [
77
"//flutter/lib/ui/channel_buffers.dart",
88
"//flutter/lib/ui/compositing.dart",
99
"//flutter/lib/ui/geometry.dart",
10+
"//flutter/lib/ui/hash_codes.dart",
1011
"//flutter/lib/ui/hooks.dart",
1112
"//flutter/lib/ui/isolate_name_server.dart",
1213
"//flutter/lib/ui/key.dart",

lib/ui/experiments/ui.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ part '../annotations.dart';
3232
part '../channel_buffers.dart';
3333
part '../compositing.dart';
3434
part '../geometry.dart';
35+
part '../hash_codes.dart';
3536
part '../hooks.dart';
3637
part '../isolate_name_server.dart';
3738
part '../key.dart';

lib/ui/hash_codes.dart

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
part of dart.ui;
5+
6+
// Examples can assume:
7+
// int foo = 0;
8+
// int bar = 0;
9+
// List<int> quux = <int>[];
10+
// List<int>? thud;
11+
// int baz = 0;
12+
13+
class _HashEnd { const _HashEnd(); }
14+
const _HashEnd _hashEnd = _HashEnd();
15+
16+
// ignore: avoid_classes_with_only_static_members
17+
/// Jenkins hash function, optimized for small integers.
18+
//
19+
// Borrowed from the dart sdk: sdk/lib/math/jenkins_smi_hash.dart.
20+
class _Jenkins {
21+
static int combine(int hash, Object? o) {
22+
assert(o is! Iterable);
23+
hash = 0x1fffffff & (hash + o.hashCode);
24+
hash = 0x1fffffff & (hash + ((0x0007ffff & hash) << 10));
25+
return hash ^ (hash >> 6);
26+
}
27+
28+
static int finish(int hash) {
29+
hash = 0x1fffffff & (hash + ((0x03ffffff & hash) << 3));
30+
hash = hash ^ (hash >> 11);
31+
return 0x1fffffff & (hash + ((0x00003fff & hash) << 15));
32+
}
33+
}
34+
35+
/// ## Deprecation
36+
///
37+
/// This function has been replaced by [Object.hash], so that it can be used
38+
/// outside of Flutter as well. The new function is a drop-in replacement.
39+
///
40+
/// The [hashList] function has also been replaced, [Object.hashAll] is the new
41+
/// function. The example above therefore is better written as:
42+
///
43+
/// ```dart
44+
/// int get hashCode => Object.hash(foo, bar, Object.hashAll(quux), baz);
45+
/// ```
46+
///
47+
/// If a parameter is nullable, then it needs special handling,
48+
/// because [Object.hashAll]'s argument is not nullable:
49+
///
50+
/// ```dart
51+
/// int get hashCode => Object.hash(foo, bar, thud == null ? null : Object.hashAll(thud!), baz);
52+
/// ```
53+
@Deprecated(
54+
'Use Object.hash() instead. '
55+
'This feature was deprecated in v3.1.0-0.0.pre.897'
56+
)
57+
int hashValues(
58+
Object? arg01, Object? arg02, [ Object? arg03 = _hashEnd,
59+
Object? arg04 = _hashEnd, Object? arg05 = _hashEnd, Object? arg06 = _hashEnd,
60+
Object? arg07 = _hashEnd, Object? arg08 = _hashEnd, Object? arg09 = _hashEnd,
61+
Object? arg10 = _hashEnd, Object? arg11 = _hashEnd, Object? arg12 = _hashEnd,
62+
Object? arg13 = _hashEnd, Object? arg14 = _hashEnd, Object? arg15 = _hashEnd,
63+
Object? arg16 = _hashEnd, Object? arg17 = _hashEnd, Object? arg18 = _hashEnd,
64+
Object? arg19 = _hashEnd, Object? arg20 = _hashEnd ]) {
65+
int result = 0;
66+
result = _Jenkins.combine(result, arg01);
67+
result = _Jenkins.combine(result, arg02);
68+
if (!identical(arg03, _hashEnd)) {
69+
result = _Jenkins.combine(result, arg03);
70+
if (!identical(arg04, _hashEnd)) {
71+
result = _Jenkins.combine(result, arg04);
72+
if (!identical(arg05, _hashEnd)) {
73+
result = _Jenkins.combine(result, arg05);
74+
if (!identical(arg06, _hashEnd)) {
75+
result = _Jenkins.combine(result, arg06);
76+
if (!identical(arg07, _hashEnd)) {
77+
result = _Jenkins.combine(result, arg07);
78+
if (!identical(arg08, _hashEnd)) {
79+
result = _Jenkins.combine(result, arg08);
80+
if (!identical(arg09, _hashEnd)) {
81+
result = _Jenkins.combine(result, arg09);
82+
if (!identical(arg10, _hashEnd)) {
83+
result = _Jenkins.combine(result, arg10);
84+
if (!identical(arg11, _hashEnd)) {
85+
result = _Jenkins.combine(result, arg11);
86+
if (!identical(arg12, _hashEnd)) {
87+
result = _Jenkins.combine(result, arg12);
88+
if (!identical(arg13, _hashEnd)) {
89+
result = _Jenkins.combine(result, arg13);
90+
if (!identical(arg14, _hashEnd)) {
91+
result = _Jenkins.combine(result, arg14);
92+
if (!identical(arg15, _hashEnd)) {
93+
result = _Jenkins.combine(result, arg15);
94+
if (!identical(arg16, _hashEnd)) {
95+
result = _Jenkins.combine(result, arg16);
96+
if (!identical(arg17, _hashEnd)) {
97+
result = _Jenkins.combine(result, arg17);
98+
if (!identical(arg18, _hashEnd)) {
99+
result = _Jenkins.combine(result, arg18);
100+
if (!identical(arg19, _hashEnd)) {
101+
result = _Jenkins.combine(result, arg19);
102+
if (!identical(arg20, _hashEnd)) {
103+
result = _Jenkins.combine(result, arg20);
104+
// I can see my house from here!
105+
}
106+
}
107+
}
108+
}
109+
}
110+
}
111+
}
112+
}
113+
}
114+
}
115+
}
116+
}
117+
}
118+
}
119+
}
120+
}
121+
}
122+
}
123+
return _Jenkins.finish(result);
124+
}
125+
126+
/// Combine the [Object.hashCode] values of an arbitrary number of objects from
127+
/// an [Iterable] into one value. This function will return the same value if
128+
/// given null as if given an empty list.
129+
///
130+
/// ## Deprecation
131+
///
132+
/// This function has been replaced by [Object.hashAll], so that it can be used
133+
/// outside of Flutter as well. The new function is a drop-in replacement, except
134+
/// that the argument must not be null.
135+
///
136+
/// There is also a new function, [Object.hashAllUnordered], which is similar
137+
/// but returns the same hash code regardless of the order of the elements in
138+
/// the provided iterable.
139+
@Deprecated(
140+
'Use Object.hashAll() or Object.hashAllUnordered() instead. '
141+
'This feature was deprecated in v3.1.0-0.0.pre.897'
142+
)
143+
int hashList(Iterable<Object?>? arguments) {
144+
int result = 0;
145+
if (arguments != null) {
146+
for (final Object? argument in arguments) {
147+
result = _Jenkins.combine(result, argument);
148+
}
149+
}
150+
return _Jenkins.finish(result);
151+
}

lib/ui/ui.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ part 'annotations.dart';
3232
part 'channel_buffers.dart';
3333
part 'compositing.dart';
3434
part 'geometry.dart';
35+
part 'hash_codes.dart';
3536
part 'hooks.dart';
3637
part 'isolate_name_server.dart';
3738
part 'key.dart';

lib/web_ui/lib/hash_codes.dart

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
part of ui;
6+
7+
class _HashEnd { const _HashEnd(); }
8+
const _HashEnd _hashEnd = _HashEnd();
9+
10+
// ignore: avoid_classes_with_only_static_members
11+
/// Jenkins hash function, optimized for small integers.
12+
//
13+
// Borrowed from the dart sdk: sdk/lib/math/jenkins_smi_hash.dart.
14+
class _Jenkins {
15+
static int combine(int hash, Object? o) {
16+
assert(o is! Iterable);
17+
hash = 0x1fffffff & (hash + o.hashCode);
18+
hash = 0x1fffffff & (hash + ((0x0007ffff & hash) << 10));
19+
return hash ^ (hash >> 6);
20+
}
21+
22+
static int finish(int hash) {
23+
hash = 0x1fffffff & (hash + ((0x03ffffff & hash) << 3));
24+
hash = hash ^ (hash >> 11);
25+
return 0x1fffffff & (hash + ((0x00003fff & hash) << 15));
26+
}
27+
}
28+
29+
/// ## Deprecation
30+
///
31+
/// This function has been replaced by [Object.hash], so that it can be used
32+
/// outside of Flutter as well. The new function is a drop-in replacement.
33+
///
34+
/// The [hashList] function has also been replaced, [Object.hashAll] is the new
35+
/// function. The example above therefore is better written as:
36+
///
37+
/// ```dart
38+
/// int get hashCode => Object.hash(foo, bar, Object.hashAll(quux), baz);
39+
/// ```
40+
///
41+
/// If a parameter is nullable, then it needs special handling,
42+
/// because [Object.hashAll]'s argument is not nullable:
43+
///
44+
/// ```dart
45+
/// int get hashCode => Object.hash(foo, bar, thud == null ? null : Object.hashAll(thud!), baz);
46+
/// ```
47+
@Deprecated(
48+
'Use Object.hash() instead. '
49+
'This feature was deprecated in v3.1.0-0.0.pre.897'
50+
)
51+
int hashValues(
52+
Object? arg01, Object? arg02, [ Object? arg03 = _hashEnd,
53+
Object? arg04 = _hashEnd, Object? arg05 = _hashEnd, Object? arg06 = _hashEnd,
54+
Object? arg07 = _hashEnd, Object? arg08 = _hashEnd, Object? arg09 = _hashEnd,
55+
Object? arg10 = _hashEnd, Object? arg11 = _hashEnd, Object? arg12 = _hashEnd,
56+
Object? arg13 = _hashEnd, Object? arg14 = _hashEnd, Object? arg15 = _hashEnd,
57+
Object? arg16 = _hashEnd, Object? arg17 = _hashEnd, Object? arg18 = _hashEnd,
58+
Object? arg19 = _hashEnd, Object? arg20 = _hashEnd ]) {
59+
int result = 0;
60+
result = _Jenkins.combine(result, arg01);
61+
result = _Jenkins.combine(result, arg02);
62+
if (!identical(arg03, _hashEnd)) {
63+
result = _Jenkins.combine(result, arg03);
64+
if (!identical(arg04, _hashEnd)) {
65+
result = _Jenkins.combine(result, arg04);
66+
if (!identical(arg05, _hashEnd)) {
67+
result = _Jenkins.combine(result, arg05);
68+
if (!identical(arg06, _hashEnd)) {
69+
result = _Jenkins.combine(result, arg06);
70+
if (!identical(arg07, _hashEnd)) {
71+
result = _Jenkins.combine(result, arg07);
72+
if (!identical(arg08, _hashEnd)) {
73+
result = _Jenkins.combine(result, arg08);
74+
if (!identical(arg09, _hashEnd)) {
75+
result = _Jenkins.combine(result, arg09);
76+
if (!identical(arg10, _hashEnd)) {
77+
result = _Jenkins.combine(result, arg10);
78+
if (!identical(arg11, _hashEnd)) {
79+
result = _Jenkins.combine(result, arg11);
80+
if (!identical(arg12, _hashEnd)) {
81+
result = _Jenkins.combine(result, arg12);
82+
if (!identical(arg13, _hashEnd)) {
83+
result = _Jenkins.combine(result, arg13);
84+
if (!identical(arg14, _hashEnd)) {
85+
result = _Jenkins.combine(result, arg14);
86+
if (!identical(arg15, _hashEnd)) {
87+
result = _Jenkins.combine(result, arg15);
88+
if (!identical(arg16, _hashEnd)) {
89+
result = _Jenkins.combine(result, arg16);
90+
if (!identical(arg17, _hashEnd)) {
91+
result = _Jenkins.combine(result, arg17);
92+
if (!identical(arg18, _hashEnd)) {
93+
result = _Jenkins.combine(result, arg18);
94+
if (!identical(arg19, _hashEnd)) {
95+
result = _Jenkins.combine(result, arg19);
96+
if (!identical(arg20, _hashEnd)) {
97+
result = _Jenkins.combine(result, arg20);
98+
// I can see my house from here!
99+
}
100+
}
101+
}
102+
}
103+
}
104+
}
105+
}
106+
}
107+
}
108+
}
109+
}
110+
}
111+
}
112+
}
113+
}
114+
}
115+
}
116+
}
117+
return _Jenkins.finish(result);
118+
}
119+
120+
/// Combine the [Object.hashCode] values of an arbitrary number of objects from
121+
/// an [Iterable] into one value. This function will return the same value if
122+
/// given null as if given an empty list.
123+
@Deprecated(
124+
'Use Object.hashAll() or Object.hashAllUnordered() instead. '
125+
'This feature was deprecated in v3.1.0-0.0.pre.897'
126+
)
127+
int hashList(Iterable<Object?>? arguments) {
128+
int result = 0;
129+
if (arguments != null) {
130+
for (final Object? argument in arguments) {
131+
result = _Jenkins.combine(result, argument);
132+
}
133+
}
134+
return _Jenkins.finish(result);
135+
}

lib/web_ui/lib/ui.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ part 'canvas.dart';
2121
part 'channel_buffers.dart';
2222
part 'compositing.dart';
2323
part 'geometry.dart';
24+
part 'hash_codes.dart';
2425
part 'initialization.dart';
2526
part 'key.dart';
2627
part 'lerp.dart';

0 commit comments

Comments
 (0)