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

Commit 0716db4

Browse files
Reverts "dart:ui - drop deprecated hash functions (#53787)" (#53794)
Reverts: #53787 Initiated by: jiahaog Reason for reverting: There are still internal users of these hash functions (b/352191023). Flutter also exports it [here](https://github.com/flutter/flutter/blob/72f83d3237a051a8b1b849abd267d4a4e80ff774/packages/flutter/lib/src/painting/basic_types.dart#L58) so its easy for developers to use them even without importing `dart:ui`. Though it's an easy fix, I'd imagine this to be a breaking change for the OSS ecosystem a Original PR Author: kevmoo Reviewed By: {jonahwilliams} This change reverts the following previous change: These were deprecated a LONG time ago
1 parent e0f1002 commit 0716db4

File tree

5 files changed

+173
-1
lines changed

5 files changed

+173
-1
lines changed

ci/licenses_golden/licenses_flutter

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42618,6 +42618,7 @@ ORIGIN: ../../../flutter/lib/ui/experiments/setup_hooks.dart + ../../../flutter/
4261842618
ORIGIN: ../../../flutter/lib/ui/experiments/ui.dart + ../../../flutter/LICENSE
4261942619
ORIGIN: ../../../flutter/lib/ui/floating_point.h + ../../../flutter/LICENSE
4262042620
ORIGIN: ../../../flutter/lib/ui/geometry.dart + ../../../flutter/LICENSE
42621+
ORIGIN: ../../../flutter/lib/ui/hash_codes.dart + ../../../flutter/LICENSE
4262142622
ORIGIN: ../../../flutter/lib/ui/hooks.dart + ../../../flutter/LICENSE
4262242623
ORIGIN: ../../../flutter/lib/ui/io_manager.cc + ../../../flutter/LICENSE
4262342624
ORIGIN: ../../../flutter/lib/ui/io_manager.h + ../../../flutter/LICENSE
@@ -45491,6 +45492,7 @@ FILE: ../../../flutter/lib/ui/experiments/setup_hooks.dart
4549145492
FILE: ../../../flutter/lib/ui/experiments/ui.dart
4549245493
FILE: ../../../flutter/lib/ui/floating_point.h
4549345494
FILE: ../../../flutter/lib/ui/geometry.dart
45495+
FILE: ../../../flutter/lib/ui/hash_codes.dart
4549445496
FILE: ../../../flutter/lib/ui/hooks.dart
4549545497
FILE: ../../../flutter/lib/ui/io_manager.cc
4549645498
FILE: ../../../flutter/lib/ui/io_manager.h

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: 3 additions & 1 deletion
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';
@@ -44,7 +45,8 @@ part '../platform_isolate.dart';
4445
part '../plugins.dart';
4546
part '../pointer.dart';
4647
part '../semantics.dart';
48+
part 'setup_hooks.dart';
4749
part '../text.dart';
4850
part '../window.dart';
51+
4952
part 'scene.dart';
50-
part 'setup_hooks.dart';

lib/ui/hash_codes.dart

Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
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+
/// Combine up to twenty objects' hash codes into one value.
36+
///
37+
/// If you only need to handle one object's hash code, then just refer to its
38+
/// [Object.hashCode] getter directly.
39+
///
40+
/// If you need to combine an arbitrary number of objects from a [List] or other
41+
/// [Iterable], use [hashList]. The output of [hashList] can be used as one of
42+
/// the arguments to this function.
43+
///
44+
/// For example:
45+
///
46+
/// ```dart
47+
/// int get hashCode => hashValues(foo, bar, hashList(quux), baz);
48+
/// ```
49+
///
50+
/// ## Deprecation
51+
///
52+
/// This function has been replaced by [Object.hash], so that it can be used
53+
/// outside of Flutter as well. The new function is a drop-in replacement.
54+
///
55+
/// The [hashList] function has also been replaced, [Object.hashAll] is the new
56+
/// function. The example above therefore is better written as:
57+
///
58+
/// ```dart
59+
/// int get hashCode => Object.hash(foo, bar, Object.hashAll(quux), baz);
60+
/// ```
61+
///
62+
/// If a parameter is nullable, then it needs special handling,
63+
/// because [Object.hashAll]'s argument is not nullable:
64+
///
65+
/// ```dart
66+
/// int get hashCode => Object.hash(foo, bar, thud == null ? null : Object.hashAll(thud!), baz);
67+
/// ```
68+
@Deprecated(
69+
'Use Object.hash() instead. '
70+
'This feature was deprecated in v3.1.0-0.0.pre.897'
71+
)
72+
int hashValues(
73+
Object? arg01, Object? arg02, [ Object? arg03 = _hashEnd,
74+
Object? arg04 = _hashEnd, Object? arg05 = _hashEnd, Object? arg06 = _hashEnd,
75+
Object? arg07 = _hashEnd, Object? arg08 = _hashEnd, Object? arg09 = _hashEnd,
76+
Object? arg10 = _hashEnd, Object? arg11 = _hashEnd, Object? arg12 = _hashEnd,
77+
Object? arg13 = _hashEnd, Object? arg14 = _hashEnd, Object? arg15 = _hashEnd,
78+
Object? arg16 = _hashEnd, Object? arg17 = _hashEnd, Object? arg18 = _hashEnd,
79+
Object? arg19 = _hashEnd, Object? arg20 = _hashEnd ]) {
80+
int result = 0;
81+
result = _Jenkins.combine(result, arg01);
82+
result = _Jenkins.combine(result, arg02);
83+
if (!identical(arg03, _hashEnd)) {
84+
result = _Jenkins.combine(result, arg03);
85+
if (!identical(arg04, _hashEnd)) {
86+
result = _Jenkins.combine(result, arg04);
87+
if (!identical(arg05, _hashEnd)) {
88+
result = _Jenkins.combine(result, arg05);
89+
if (!identical(arg06, _hashEnd)) {
90+
result = _Jenkins.combine(result, arg06);
91+
if (!identical(arg07, _hashEnd)) {
92+
result = _Jenkins.combine(result, arg07);
93+
if (!identical(arg08, _hashEnd)) {
94+
result = _Jenkins.combine(result, arg08);
95+
if (!identical(arg09, _hashEnd)) {
96+
result = _Jenkins.combine(result, arg09);
97+
if (!identical(arg10, _hashEnd)) {
98+
result = _Jenkins.combine(result, arg10);
99+
if (!identical(arg11, _hashEnd)) {
100+
result = _Jenkins.combine(result, arg11);
101+
if (!identical(arg12, _hashEnd)) {
102+
result = _Jenkins.combine(result, arg12);
103+
if (!identical(arg13, _hashEnd)) {
104+
result = _Jenkins.combine(result, arg13);
105+
if (!identical(arg14, _hashEnd)) {
106+
result = _Jenkins.combine(result, arg14);
107+
if (!identical(arg15, _hashEnd)) {
108+
result = _Jenkins.combine(result, arg15);
109+
if (!identical(arg16, _hashEnd)) {
110+
result = _Jenkins.combine(result, arg16);
111+
if (!identical(arg17, _hashEnd)) {
112+
result = _Jenkins.combine(result, arg17);
113+
if (!identical(arg18, _hashEnd)) {
114+
result = _Jenkins.combine(result, arg18);
115+
if (!identical(arg19, _hashEnd)) {
116+
result = _Jenkins.combine(result, arg19);
117+
if (!identical(arg20, _hashEnd)) {
118+
result = _Jenkins.combine(result, arg20);
119+
// I can see my house from here!
120+
}
121+
}
122+
}
123+
}
124+
}
125+
}
126+
}
127+
}
128+
}
129+
}
130+
}
131+
}
132+
}
133+
}
134+
}
135+
}
136+
}
137+
}
138+
return _Jenkins.finish(result);
139+
}
140+
141+
/// Combine the [Object.hashCode] values of an arbitrary number of objects from
142+
/// an [Iterable] into one value. This function will return the same value if
143+
/// given null as if given an empty list.
144+
///
145+
/// ## Deprecation
146+
///
147+
/// This function has been replaced by [Object.hashAll], so that it can be used
148+
/// outside of Flutter as well. The new function is a drop-in replacement, except
149+
/// that the argument must not be null.
150+
///
151+
/// There is also a new function, [Object.hashAllUnordered], which is similar
152+
/// but returns the same hash code regardless of the order of the elements in
153+
/// the provided iterable.
154+
@Deprecated(
155+
'Use Object.hashAll() or Object.hashAllUnordered() instead. '
156+
'This feature was deprecated in v3.1.0-0.0.pre.897'
157+
)
158+
int hashList(Iterable<Object?>? arguments) {
159+
int result = 0;
160+
if (arguments != null) {
161+
for (final Object? argument in arguments) {
162+
result = _Jenkins.combine(result, argument);
163+
}
164+
}
165+
return _Jenkins.finish(result);
166+
}

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';

0 commit comments

Comments
 (0)