Skip to content

Commit 87c64bc

Browse files
authored
Deprecates hashValues and hashList (flutter#30674)
* deprecate hashValues and hashList * rm unused imports * missing periods and const lists * improves hashing of lists * ignore: avoid_classes_with_only_static_members * migrate new classes * refactor: update version of deprecation
1 parent a5eefc8 commit 87c64bc

27 files changed

Lines changed: 153 additions & 137 deletions

lib/ui/geometry.dart

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ abstract class OffsetBase {
9191
}
9292

9393
@override
94-
int get hashCode => hashValues(_dx, _dy);
94+
int get hashCode => Object.hash(_dx, _dy);
9595

9696
@override
9797
String toString() => 'OffsetBase(${_dx.toStringAsFixed(1)}, ${_dy.toStringAsFixed(1)})';
@@ -341,7 +341,7 @@ class Offset extends OffsetBase {
341341
}
342342

343343
@override
344-
int get hashCode => hashValues(dx, dy);
344+
int get hashCode => Object.hash(dx, dy);
345345

346346
@override
347347
String toString() => 'Offset(${dx.toStringAsFixed(1)}, ${dy.toStringAsFixed(1)})';
@@ -613,7 +613,7 @@ class Size extends OffsetBase {
613613
}
614614

615615
@override
616-
int get hashCode => hashValues(_dx, _dy);
616+
int get hashCode => Object.hash(_dx, _dy);
617617

618618
@override
619619
String toString() => 'Size(${width.toStringAsFixed(1)}, ${height.toStringAsFixed(1)})';
@@ -907,7 +907,7 @@ class Rect {
907907
}
908908

909909
@override
910-
int get hashCode => hashValues(left, top, right, bottom);
910+
int get hashCode => Object.hash(left, top, right, bottom);
911911

912912
@override
913913
String toString() => 'Rect.fromLTRB(${left.toStringAsFixed(1)}, ${top.toStringAsFixed(1)}, ${right.toStringAsFixed(1)}, ${bottom.toStringAsFixed(1)})';
@@ -1033,7 +1033,7 @@ class Radius {
10331033
}
10341034

10351035
@override
1036-
int get hashCode => hashValues(x, y);
1036+
int get hashCode => Object.hash(x, y);
10371037

10381038
@override
10391039
String toString() {
@@ -1645,7 +1645,7 @@ class RRect {
16451645
}
16461646

16471647
@override
1648-
int get hashCode => hashValues(left, top, right, bottom,
1648+
int get hashCode => Object.hash(left, top, right, bottom,
16491649
tlRadiusX, tlRadiusY, trRadiusX, trRadiusY,
16501650
blRadiusX, blRadiusY, brRadiusX, brRadiusY);
16511651

lib/ui/hash_codes.dart

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5-
65
// @dart = 2.12
76
part of dart.ui;
87

98
class _HashEnd { const _HashEnd(); }
109
const _HashEnd _hashEnd = _HashEnd();
1110

11+
// ignore: avoid_classes_with_only_static_members
1212
/// Jenkins hash function, optimized for small integers.
1313
//
1414
// Borrowed from the dart sdk: sdk/lib/math/jenkins_smi_hash.dart.
@@ -41,6 +41,10 @@ class _Jenkins {
4141
/// ```dart
4242
/// int hashCode => hashValues(foo, bar, hashList(quux), baz);
4343
/// ```
44+
@Deprecated(
45+
'Use Object.hash() instead. '
46+
'This feature was deprecated in v3.1.0-0.0.pre.897'
47+
)
4448
int hashValues(
4549
Object? arg01, Object? arg02, [ Object? arg03 = _hashEnd,
4650
Object? arg04 = _hashEnd, Object? arg05 = _hashEnd, Object? arg06 = _hashEnd,
@@ -113,6 +117,10 @@ int hashValues(
113117
/// Combine the [Object.hashCode] values of an arbitrary number of objects from
114118
/// an [Iterable] into one value. This function will return the same value if
115119
/// given null as if given an empty list.
120+
@Deprecated(
121+
'Use Object.hashAll() or Object.hashAllUnordered() instead. '
122+
'This feature was deprecated in v3.1.0-0.0.pre.897'
123+
)
116124
int hashList(Iterable<Object?>? arguments) {
117125
int result = 0;
118126
if (arguments != null) {

lib/ui/painting.dart

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3009,7 +3009,7 @@ class MaskFilter {
30093009
}
30103010

30113011
@override
3012-
int get hashCode => hashValues(_style, _sigma);
3012+
int get hashCode => Object.hash(_style, _sigma);
30133013

30143014
@override
30153015
String toString() => 'MaskFilter.blur($_style, ${_sigma.toStringAsFixed(1)})';
@@ -3168,7 +3168,7 @@ class ColorFilter implements ImageFilter {
31683168
}
31693169

31703170
@override
3171-
int get hashCode => hashValues(_color, _blendMode, hashList(_matrix), _type);
3171+
int get hashCode => Object.hash(_color, _blendMode, _matrix == null ? null : Object.hashAll(_matrix!), _type);
31723172

31733173
@override
31743174
String get _shortDescription {
@@ -3342,7 +3342,7 @@ class _MatrixImageFilter implements ImageFilter {
33423342
}
33433343

33443344
@override
3345-
int get hashCode => hashValues(filterQuality, hashList(data));
3345+
int get hashCode => Object.hash(filterQuality, Object.hashAll(data));
33463346
}
33473347

33483348
class _GaussianBlurImageFilter implements ImageFilter {
@@ -3383,7 +3383,7 @@ class _GaussianBlurImageFilter implements ImageFilter {
33833383
}
33843384

33853385
@override
3386-
int get hashCode => hashValues(sigmaX, sigmaY);
3386+
int get hashCode => Object.hash(sigmaX, sigmaY);
33873387
}
33883388

33893389
class _DilateImageFilter implements ImageFilter {
@@ -3412,7 +3412,7 @@ class _DilateImageFilter implements ImageFilter {
34123412
}
34133413

34143414
@override
3415-
int get hashCode => hashValues(radiusX, radiusY);
3415+
int get hashCode => Object.hash(radiusX, radiusY);
34163416
}
34173417

34183418
class _ErodeImageFilter implements ImageFilter {
@@ -3471,7 +3471,7 @@ class _ComposeImageFilter implements ImageFilter {
34713471
}
34723472

34733473
@override
3474-
int get hashCode => hashValues(innerFilter, outerFilter);
3474+
int get hashCode => Object.hash(innerFilter, outerFilter);
34753475
}
34763476

34773477
/// An [ImageFilter] that is backed by a native SkImageFilter.
@@ -4048,7 +4048,7 @@ class _FragmentShader extends Shader {
40484048
}
40494049

40504050
@override
4051-
int get hashCode => hashValues(_builder, hashList(_floatUniforms), hashList(_samplerUniforms));
4051+
int get hashCode => Object.hash(_builder, Object.hashAll(_floatUniforms), Object.hashAll(_samplerUniforms));
40524052
}
40534053

40544054
/// Defines how a list of points is interpreted when drawing a set of triangles.
@@ -5508,7 +5508,7 @@ class Shadow {
55085508
}
55095509

55105510
@override
5511-
int get hashCode => hashValues(color, offset, blurRadius);
5511+
int get hashCode => Object.hash(color, offset, blurRadius);
55125512

55135513
// Serialize [shadows] into ByteData. The format is a single uint_32_t at
55145514
// the beginning indicating the number of shadows, followed by _kBytesPerShadow

lib/ui/platform_dispatcher.dart

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1689,7 +1689,7 @@ class DisplayFeature {
16891689
}
16901690

16911691
@override
1692-
int get hashCode => hashValues(bounds, type, state);
1692+
int get hashCode => Object.hash(bounds, type, state);
16931693

16941694
@override
16951695
String toString() {
@@ -2016,13 +2016,7 @@ class Locale {
20162016
}
20172017

20182018
@override
2019-
int get hashCode => _hashCode[this] ??= hashValues(
2020-
languageCode,
2021-
scriptCode,
2022-
countryCode == '' ? null : countryCode,
2023-
);
2024-
// Memoize hashCode since languageCode and countryCode require lookups.
2025-
static final Expando<int> _hashCode = Expando<int>();
2019+
int get hashCode => Object.hash(languageCode, scriptCode, countryCode == '' ? null : countryCode);
20262020

20272021
static Locale? _cachedLocale;
20282022
static String? _cachedLocaleString;

lib/ui/text.dart

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -927,7 +927,7 @@ class FontFeature {
927927
}
928928

929929
@override
930-
int get hashCode => hashValues(feature, value);
930+
int get hashCode => Object.hash(feature, value);
931931

932932
@override
933933
String toString() => "FontFeature('$feature', $value)";
@@ -988,7 +988,7 @@ class FontVariation {
988988
}
989989

990990
@override
991-
int get hashCode => hashValues(axis, value);
991+
int get hashCode => Object.hash(axis, value);
992992

993993
@override
994994
String toString() => "FontVariation('$axis', $value)";
@@ -1236,7 +1236,7 @@ class TextHeightBehavior {
12361236

12371237
@override
12381238
int get hashCode {
1239-
return hashValues(
1239+
return Object.hash(
12401240
applyHeightToFirstAscent,
12411241
applyHeightToLastDescent,
12421242
leadingDistribution.index,
@@ -1540,7 +1540,23 @@ class TextStyle {
15401540
}
15411541

15421542
@override
1543-
int get hashCode => hashValues(hashList(_encoded), _leadingDistribution, _fontFamily, _fontFamilyFallback, _fontSize, _letterSpacing, _wordSpacing, _height, _locale, _background, _foreground, hashList(_shadows), _decorationThickness, hashList(_fontFeatures), hashList(_fontVariations));
1543+
int get hashCode => Object.hash(
1544+
Object.hashAll(_encoded),
1545+
_leadingDistribution,
1546+
_fontFamily,
1547+
_fontFamilyFallback,
1548+
_fontSize,
1549+
_letterSpacing,
1550+
_wordSpacing,
1551+
_height,
1552+
_locale,
1553+
_background,
1554+
_foreground,
1555+
_shadows == null ? null : Object.hashAll(_shadows!),
1556+
_decorationThickness,
1557+
_fontFeatures == null ? null : Object.hashAll(_fontFeatures!),
1558+
_fontVariations == null ? null : Object.hashAll(_fontVariations!),
1559+
);
15441560

15451561
@override
15461562
String toString() {
@@ -1785,7 +1801,7 @@ class ParagraphStyle {
17851801
}
17861802

17871803
@override
1788-
int get hashCode => hashValues(hashList(_encoded), _fontFamily, _fontSize, _height, _ellipsis, _locale, _leadingDistribution);
1804+
int get hashCode => Object.hash(Object.hashAll(_encoded), _fontFamily, _fontSize, _height, _ellipsis, _locale, _leadingDistribution);
17891805

17901806
@override
17911807
String toString() {
@@ -1979,7 +1995,7 @@ class StrutStyle {
19791995
}
19801996

19811997
@override
1982-
int get hashCode => hashValues(hashList(_encoded.buffer.asInt8List()), _fontFamily, _leadingDistribution);
1998+
int get hashCode => Object.hash(Object.hashAll(_encoded.buffer.asInt8List()), _fontFamily, _leadingDistribution);
19831999

19842000
}
19852001

@@ -2145,7 +2161,7 @@ class TextBox {
21452161
}
21462162

21472163
@override
2148-
int get hashCode => hashValues(left, top, right, bottom, direction);
2164+
int get hashCode => Object.hash(left, top, right, bottom, direction);
21492165

21502166
@override
21512167
String toString() => 'TextBox.fromLTRBD(${left.toStringAsFixed(1)}, ${top.toStringAsFixed(1)}, ${right.toStringAsFixed(1)}, ${bottom.toStringAsFixed(1)}, $direction)';
@@ -2252,7 +2268,7 @@ class TextPosition {
22522268
}
22532269

22542270
@override
2255-
int get hashCode => hashValues(offset, affinity);
2271+
int get hashCode => Object.hash(offset, affinity);
22562272

22572273
@override
22582274
String toString() {
@@ -2336,7 +2352,7 @@ class TextRange {
23362352
}
23372353

23382354
@override
2339-
int get hashCode => hashValues(
2355+
int get hashCode => Object.hash(
23402356
start.hashCode,
23412357
end.hashCode,
23422358
);
@@ -2619,7 +2635,7 @@ class LineMetrics {
26192635
}
26202636

26212637
@override
2622-
int get hashCode => hashValues(hardBreak, ascent, descent, unscaledAscent, height, width, left, baseline, lineNumber);
2638+
int get hashCode => Object.hash(hardBreak, ascent, descent, unscaledAscent, height, width, left, baseline, lineNumber);
26232639

26242640
@override
26252641
String toString() {

lib/ui/window.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -983,7 +983,7 @@ class GestureSettings {
983983
}
984984

985985
@override
986-
int get hashCode => hashValues(physicalTouchSlop, physicalDoubleTapSlop);
986+
int get hashCode => Object.hash(physicalTouchSlop, physicalDoubleTapSlop);
987987

988988
@override
989989
String toString() => 'GestureSettings(physicalTouchSlop: $physicalTouchSlop, physicalDoubleTapSlop: $physicalDoubleTapSlop)';

lib/web_ui/lib/geometry.dart

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ abstract class OffsetBase {
2828
}
2929

3030
@override
31-
int get hashCode => hashValues(_dx, _dy);
31+
int get hashCode => Object.hash(_dx, _dy);
3232

3333
@override
3434
String toString() => 'OffsetBase(${_dx.toStringAsFixed(1)}, ${_dy.toStringAsFixed(1)})';
@@ -82,7 +82,7 @@ class Offset extends OffsetBase {
8282
}
8383

8484
@override
85-
int get hashCode => hashValues(dx, dy);
85+
int get hashCode => Object.hash(dx, dy);
8686

8787
@override
8888
String toString() => 'Offset(${dx.toStringAsFixed(1)}, ${dy.toStringAsFixed(1)})';
@@ -169,7 +169,7 @@ class Size extends OffsetBase {
169169
}
170170

171171
@override
172-
int get hashCode => hashValues(_dx, _dy);
172+
int get hashCode => Object.hash(_dx, _dy);
173173

174174
@override
175175
String toString() => 'Size(${width.toStringAsFixed(1)}, ${height.toStringAsFixed(1)})';
@@ -321,7 +321,7 @@ class Rect {
321321
}
322322

323323
@override
324-
int get hashCode => hashValues(left, top, right, bottom);
324+
int get hashCode => Object.hash(left, top, right, bottom);
325325

326326
@override
327327
String toString() => 'Rect.fromLTRB(${left.toStringAsFixed(1)}, ${top.toStringAsFixed(1)}, ${right.toStringAsFixed(1)}, ${bottom.toStringAsFixed(1)})';
@@ -374,7 +374,7 @@ class Radius {
374374
}
375375

376376
@override
377-
int get hashCode => hashValues(x, y);
377+
int get hashCode => Object.hash(x, y);
378378

379379
@override
380380
String toString() {
@@ -870,7 +870,7 @@ class RRect {
870870
}
871871

872872
@override
873-
int get hashCode => hashValues(left, top, right, bottom,
873+
int get hashCode => Object.hash(left, top, right, bottom,
874874
tlRadiusX, tlRadiusY, trRadiusX, trRadiusY,
875875
blRadiusX, blRadiusY, brRadiusX, brRadiusY);
876876

0 commit comments

Comments
 (0)