diff --git a/examples/stocks/lib/stock_row.dart b/examples/stocks/lib/stock_row.dart index 1d61b2967e4..134cc1deef8 100644 --- a/examples/stocks/lib/stock_row.dart +++ b/examples/stocks/lib/stock_row.dart @@ -21,7 +21,7 @@ class StockRowPartKey extends Key { && stock == typedOther.stock && part == typedOther.part; } - int get hashCode => 37 * (37 * (37 * (373) + identityHashCode(keySalt)) + identityHashCode(stock)) + identityHashCode(part); + int get hashCode => hashValues(keySalt, stock, part); String toString() => '[$runtimeType ${keySalt.toString().split(".")[1]}:${stock.symbol}:${part.toString().split(".")[1]}]'; } diff --git a/packages/flutter/lib/src/material/theme_data.dart b/packages/flutter/lib/src/material/theme_data.dart index 5ee6a07063b..4cdd06e4de6 100644 --- a/packages/flutter/lib/src/material/theme_data.dart +++ b/packages/flutter/lib/src/material/theme_data.dart @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import 'dart:ui' show Color; +import 'dart:ui' show Color, hashValues; import 'colors.dart'; import 'icon_theme_data.dart'; @@ -153,19 +153,19 @@ class ThemeData { (otherData.accentColorBrightness == accentColorBrightness); } int get hashCode { - int value = 373; - value = 37 * value + brightness.hashCode; - value = 37 * value + primarySwatch.hashCode; - value = 37 * value + canvasColor.hashCode; - value = 37 * value + cardColor.hashCode; - value = 37 * value + dividerColor.hashCode; - value = 37 * value + hintColor.hashCode; - value = 37 * value + highlightColor.hashCode; - value = 37 * value + hintOpacity.hashCode; - value = 37 * value + text.hashCode; - value = 37 * value + primaryColorBrightness.hashCode; - value = 37 * value + accentColorBrightness.hashCode; - return value; + return hashValues( + brightness, + primarySwatch, + canvasColor, + cardColor, + dividerColor, + hintColor, + highlightColor, + hintOpacity, + text, + primaryColorBrightness, + accentColorBrightness + ); } String toString() => '$primaryColor $brightness etc...'; diff --git a/packages/flutter/lib/src/material/time_picker.dart b/packages/flutter/lib/src/material/time_picker.dart index f495e2b1b24..b12f791fd1b 100644 --- a/packages/flutter/lib/src/material/time_picker.dart +++ b/packages/flutter/lib/src/material/time_picker.dart @@ -84,12 +84,7 @@ class TimeOfDay { && typedOther.minute == minute; } - int get hashCode { - int value = 373; - value = 37 * value + hour.hashCode; - value = 37 * value + minute.hashCode; - return value; - } + int get hashCode => hashValues(hour, minute); // TODO(ianh): Localize. String toString() => '$hourOfPeriodLabel:$minuteLabel $periodLabel'; diff --git a/packages/flutter/lib/src/painting/basic_types.dart b/packages/flutter/lib/src/painting/basic_types.dart index 88209a16628..2c40e5c7dd0 100644 --- a/packages/flutter/lib/src/painting/basic_types.dart +++ b/packages/flutter/lib/src/painting/basic_types.dart @@ -18,4 +18,6 @@ export 'dart:ui' show TextBaseline, TextDecoration, TextDecorationStyle, - VoidCallback; + VoidCallback, + hashValues, + hashList; diff --git a/packages/flutter/lib/src/painting/box_painter.dart b/packages/flutter/lib/src/painting/box_painter.dart index 40446b31e96..03c7cb7adb2 100644 --- a/packages/flutter/lib/src/painting/box_painter.dart +++ b/packages/flutter/lib/src/painting/box_painter.dart @@ -39,12 +39,7 @@ class BorderSide { width == typedOther.width; } - int get hashCode { - int value = 373; - value = 37 * value + color.hashCode; - value = 37 * value + width.hashCode; - return value; - } + int get hashCode => hashValues(color, width); String toString() => 'BorderSide($color, $width)'; } @@ -96,14 +91,7 @@ class Border { left == typedOther.left; } - int get hashCode { - int value = 373; - value = 37 * value + top.hashCode; - value = 37 * value + right.hashCode; - value = 37 * value + bottom.hashCode; - value = 37 * value + left.hashCode; - return value; - } + int get hashCode => hashValues(top, right, bottom, left); String toString() => 'Border($top, $right, $bottom, $left)'; } @@ -198,14 +186,7 @@ class BoxShadow { spreadRadius == typedOther.spreadRadius; } - int get hashCode { - int value = 373; - value = 37 * value + color.hashCode; - value = 37 * value + offset.hashCode; - value = 37 * value + blurRadius.hashCode; - value = 37 * value + spreadRadius.hashCode; - return value; - } + int get hashCode => hashValues(color, offset, blurRadius, spreadRadius); String toString() => 'BoxShadow($color, $offset, $blurRadius, $spreadRadius)'; } @@ -281,25 +262,7 @@ class LinearGradient extends Gradient { return true; } - int get hashCode { - int value = 373; - value = 37 * value + begin.hashCode; - value = 37 * value + end.hashCode; - value = 37 * value + tileMode.hashCode; - if (colors != null) { - for (int i = 0; i < colors.length; i += 1) - value = 37 * value + colors[i].hashCode; - } else { - value = 37 * value + null.hashCode; - } - if (stops != null) { - for (int i = 0; i < stops.length; i += 1) - value = 37 * value + stops[i].hashCode; - } else { - value = 37 * value + null.hashCode; - } - return value; - } + int get hashCode => hashValues(begin, end, tileMode, hashList(colors), hashList(stops)); String toString() { return 'LinearGradient($begin, $end, $colors, $stops, $tileMode)'; @@ -373,25 +336,7 @@ class RadialGradient extends Gradient { return true; } - int get hashCode { - int value = 373; - value = 37 * value + center.hashCode; - value = 37 * value + radius.hashCode; - value = 37 * value + tileMode.hashCode; - if (colors != null) { - for (int i = 0; i < colors.length; i += 1) - value = 37 * value + colors[i].hashCode; - } else { - value = 37 * value + null.hashCode; - } - if (stops != null) { - for (int i = 0; i < stops.length; i += 1) - value = 37 * value + stops[i].hashCode; - } else { - value = 37 * value + null.hashCode; - } - return value; - } + int get hashCode => hashValues(center, radius, tileMode, hashList(colors), hashList(stops)); String toString() { return 'RadialGradient($center, $radius, $colors, $stops, $tileMode)'; @@ -581,12 +526,7 @@ class FractionalOffset { return x == typedOther.x && y == typedOther.y; } - int get hashCode { - int value = 373; - value = 37 * value + x.hashCode; - value = 37 * value + y.hashCode; - return value; - } + int get hashCode => hashValues(x, y); static FractionalOffset lerp(FractionalOffset a, FractionalOffset b, double t) { if (a == null && b == null) return null; @@ -682,16 +622,7 @@ class BackgroundImage { _imageResource == typedOther._imageResource; } - int get hashCode { - int value = 373; - value = 37 * value + fit.hashCode; - value = 37 * value + repeat.hashCode; - value = 37 * value + centerSlice.hashCode; - value = 37 * value + colorFilter.hashCode; - value = 37 * value + alignment.hashCode; - value = 37 * value + _imageResource.hashCode; - return value; - } + int get hashCode => hashValues(fit, repeat, centerSlice, colorFilter, alignment, _imageResource); String toString() => 'BackgroundImage($fit, $repeat)'; } @@ -844,15 +775,15 @@ class BoxDecoration extends Decoration { } int get hashCode { - int value = 373; - value = 37 * value + backgroundColor.hashCode; - value = 37 * value + backgroundImage.hashCode; - value = 37 * value + border.hashCode; - value = 37 * value + borderRadius.hashCode; - value = 37 * value + boxShadow.hashCode; - value = 37 * value + gradient.hashCode; - value = 37 * value + shape.hashCode; - return value; + return hashValues( + backgroundColor, + backgroundImage, + border, + borderRadius, + boxShadow, + gradient, + shape + ); } String toString([String prefix = '']) { diff --git a/packages/flutter/lib/src/painting/colors.dart b/packages/flutter/lib/src/painting/colors.dart index d8190688fc0..66b2042bb60 100644 --- a/packages/flutter/lib/src/painting/colors.dart +++ b/packages/flutter/lib/src/painting/colors.dart @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import 'dart:ui' show Color, lerpDouble; +import 'dart:ui' show Color, lerpDouble, hashValues; class HSVColor { const HSVColor.fromAHSV(this.alpha, this.hue, this.saturation, this.value); @@ -113,14 +113,7 @@ class HSVColor { && typedOther.value == value; } - int get hashCode { - int value = 373; - value = 37 * value + alpha.hashCode; - value = 37 * value + hue.hashCode; - value = 37 * value + saturation.hashCode; - value = 37 * value + value.hashCode; - return value; - } + int get hashCode => hashValues(alpha, hue, saturation, value); String toString() => "HSVColor($alpha, $hue, $saturation, $value)"; } diff --git a/packages/flutter/lib/src/painting/edge_dims.dart b/packages/flutter/lib/src/painting/edge_dims.dart index 7e3c972fb33..cbda59da8ff 100644 --- a/packages/flutter/lib/src/painting/edge_dims.dart +++ b/packages/flutter/lib/src/painting/edge_dims.dart @@ -3,6 +3,7 @@ // found in the LICENSE file. import 'dart:ui' as ui; +import 'dart:ui' show hashValues; /// An immutable set of offsets in each of the four cardinal directions. /// @@ -136,14 +137,7 @@ class EdgeDims { left == typedOther.left; } - int get hashCode { - int value = 373; - value = 37 * value + top.hashCode; - value = 37 * value + left.hashCode; - value = 37 * value + bottom.hashCode; - value = 37 * value + right.hashCode; - return value; - } + int get hashCode => hashValues(top, left, bottom, right); String toString() => "EdgeDims($top, $right, $bottom, $left)"; } diff --git a/packages/flutter/lib/src/painting/text_painter.dart b/packages/flutter/lib/src/painting/text_painter.dart index 7f50a578c54..9840c350b4d 100644 --- a/packages/flutter/lib/src/painting/text_painter.dart +++ b/packages/flutter/lib/src/painting/text_painter.dart @@ -78,13 +78,7 @@ class StyledTextSpan extends TextSpan { return true; } - int get hashCode { - int value = 373; - value = 37 * value + style.hashCode; - for (TextSpan child in children) - value = 37 * value + child.hashCode; - return value; - } + int get hashCode => hashValues(style, hashList(children)); String toString([String prefix = '']) { List result = []; diff --git a/packages/flutter/lib/src/painting/text_style.dart b/packages/flutter/lib/src/painting/text_style.dart index 512d9aa3ded..49cbfd31c37 100644 --- a/packages/flutter/lib/src/painting/text_style.dart +++ b/packages/flutter/lib/src/painting/text_style.dart @@ -163,21 +163,20 @@ class TextStyle { } int get hashCode { - // Use Quiver: https://github.com/domokit/mojo/issues/236 - int value = 373; - value = 37 * value + inherit.hashCode; - value = 37 * value + color.hashCode; - value = 37 * value + fontFamily.hashCode; - value = 37 * value + fontSize.hashCode; - value = 37 * value + fontWeight.hashCode; - value = 37 * value + fontStyle.hashCode; - value = 37 * value + letterSpacing.hashCode; - value = 37 * value + textAlign.hashCode; - value = 37 * value + textBaseline.hashCode; - value = 37 * value + decoration.hashCode; - value = 37 * value + decorationColor.hashCode; - value = 37 * value + decorationStyle.hashCode; - return value; + return hashValues( + super.hashCode, + color, + fontFamily, + fontSize, + fontWeight, + fontStyle, + letterSpacing, + textAlign, + textBaseline, + decoration, + decorationColor, + decorationStyle + ); } String toString([String prefix = '']) { diff --git a/packages/flutter/lib/src/rendering/box.dart b/packages/flutter/lib/src/rendering/box.dart index f13114859d6..980fec0d4ec 100644 --- a/packages/flutter/lib/src/rendering/box.dart +++ b/packages/flutter/lib/src/rendering/box.dart @@ -4,6 +4,7 @@ import 'dart:math' as math; import 'dart:ui' as ui; +import 'dart:ui' show hashValues; import 'package:flutter/animation.dart'; import 'package:flutter/gestures.dart'; @@ -272,12 +273,7 @@ class BoxConstraints extends Constraints { int get hashCode { assert(isNormalized); - int value = 373; - value = 37 * value + minWidth.hashCode; - value = 37 * value + maxWidth.hashCode; - value = 37 * value + minHeight.hashCode; - value = 37 * value + maxHeight.hashCode; - return value; + return hashValues(minWidth, maxWidth, minHeight, maxHeight); } String toString() { diff --git a/packages/flutter/lib/src/rendering/stack.dart b/packages/flutter/lib/src/rendering/stack.dart index 16121ecb8dd..cf31f1fd408 100644 --- a/packages/flutter/lib/src/rendering/stack.dart +++ b/packages/flutter/lib/src/rendering/stack.dart @@ -3,7 +3,7 @@ // found in the LICENSE file. import 'dart:math' as math; -import 'dart:ui' show lerpDouble; +import 'dart:ui' show lerpDouble, hashValues; import 'box.dart'; import 'object.dart'; @@ -123,14 +123,7 @@ class RelativeRect { bottom == typedOther.bottom; } - int get hashCode { - int value = 373; - value = 37 * value + left.hashCode; - value = 37 * value + top.hashCode; - value = 37 * value + right.hashCode; - value = 37 * value + bottom.hashCode; - return value; - } + int get hashCode => hashValues(left, top, right, bottom); String toString() => "RelativeRect.fromLTRB(${left.toStringAsFixed(1)}, ${top.toStringAsFixed(1)}, ${right.toStringAsFixed(1)}, ${bottom.toStringAsFixed(1)})"; } diff --git a/packages/flutter/lib/src/widgets/framework.dart b/packages/flutter/lib/src/widgets/framework.dart index 62496dfb9b4..5e229b30905 100644 --- a/packages/flutter/lib/src/widgets/framework.dart +++ b/packages/flutter/lib/src/widgets/framework.dart @@ -7,6 +7,7 @@ import 'dart:collection'; import 'package:flutter/rendering.dart'; +export 'dart:ui' show hashValues, hashList; export 'package:flutter/rendering.dart' show debugPrint; // KEYS diff --git a/packages/flutter/lib/src/widgets/mixed_viewport.dart b/packages/flutter/lib/src/widgets/mixed_viewport.dart index 17582503c63..88dc7556cc2 100644 --- a/packages/flutter/lib/src/widgets/mixed_viewport.dart +++ b/packages/flutter/lib/src/widgets/mixed_viewport.dart @@ -63,7 +63,7 @@ class _ChildKey { return type == typedOther.type && key == typedOther.key; } - int get hashCode => ((373 * 37) + type.hashCode) * 37 + key.hashCode; + int get hashCode => hashValues(type, key); String toString() => "_ChildKey(type: $type, key: $key)"; } diff --git a/packages/flutter/lib/src/widgets/page_storage.dart b/packages/flutter/lib/src/widgets/page_storage.dart index 7bd1e18d2ca..dd73ec5b928 100644 --- a/packages/flutter/lib/src/widgets/page_storage.dart +++ b/packages/flutter/lib/src/widgets/page_storage.dart @@ -30,16 +30,7 @@ class _StorageEntryIdentifier { } return true; } - int get hashCode { - int value = 373; - value = 37 * value + clientType.hashCode; - value = 37 * value + scopeKey.hashCode; - if (keys != null) { - for (Key key in keys) - value = 37 * value + key.hashCode; - } - return value; - } + int get hashCode => hashValues(clientType, scopeKey, hashList(keys)); } class PageStorageBucket {