Commit d8a3ed3e authored by Ian Hickson's avatar Ian Hickson

Use hashValues instead of hard-coded hashCode getters

parent 43d97668
......@@ -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]}]';
}
......
......@@ -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...';
......
......@@ -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';
......
......@@ -18,4 +18,6 @@ export 'dart:ui' show
TextBaseline,
TextDecoration,
TextDecorationStyle,
VoidCallback;
VoidCallback,
hashValues,
hashList;
......@@ -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 = '']) {
......
......@@ -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)";
}
......@@ -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)";
}
......@@ -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<String> result = <String>[];
......
......@@ -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 = '']) {
......
......@@ -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() {
......
......@@ -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)})";
}
......
......@@ -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
......
......@@ -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)";
}
......
......@@ -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 {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment