Commit e78d6cbc authored by Ian Hickson's avatar Ian Hickson

Merge pull request #857 from Hixie/hashCodes

Use hashValues instead of hard-coded hashCode getters
parents 1ab83e66 d8a3ed3e
...@@ -21,7 +21,7 @@ class StockRowPartKey extends Key { ...@@ -21,7 +21,7 @@ class StockRowPartKey extends Key {
&& stock == typedOther.stock && stock == typedOther.stock
&& part == typedOther.part; && 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]}]'; String toString() => '[$runtimeType ${keySalt.toString().split(".")[1]}:${stock.symbol}:${part.toString().split(".")[1]}]';
} }
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
import 'dart:ui' show Color; import 'dart:ui' show Color, hashValues;
import 'colors.dart'; import 'colors.dart';
import 'icon_theme_data.dart'; import 'icon_theme_data.dart';
...@@ -153,19 +153,19 @@ class ThemeData { ...@@ -153,19 +153,19 @@ class ThemeData {
(otherData.accentColorBrightness == accentColorBrightness); (otherData.accentColorBrightness == accentColorBrightness);
} }
int get hashCode { int get hashCode {
int value = 373; return hashValues(
value = 37 * value + brightness.hashCode; brightness,
value = 37 * value + primarySwatch.hashCode; primarySwatch,
value = 37 * value + canvasColor.hashCode; canvasColor,
value = 37 * value + cardColor.hashCode; cardColor,
value = 37 * value + dividerColor.hashCode; dividerColor,
value = 37 * value + hintColor.hashCode; hintColor,
value = 37 * value + highlightColor.hashCode; highlightColor,
value = 37 * value + hintOpacity.hashCode; hintOpacity,
value = 37 * value + text.hashCode; text,
value = 37 * value + primaryColorBrightness.hashCode; primaryColorBrightness,
value = 37 * value + accentColorBrightness.hashCode; accentColorBrightness
return value; );
} }
String toString() => '$primaryColor $brightness etc...'; String toString() => '$primaryColor $brightness etc...';
......
...@@ -84,12 +84,7 @@ class TimeOfDay { ...@@ -84,12 +84,7 @@ class TimeOfDay {
&& typedOther.minute == minute; && typedOther.minute == minute;
} }
int get hashCode { int get hashCode => hashValues(hour, minute);
int value = 373;
value = 37 * value + hour.hashCode;
value = 37 * value + minute.hashCode;
return value;
}
// TODO(ianh): Localize. // TODO(ianh): Localize.
String toString() => '$hourOfPeriodLabel:$minuteLabel $periodLabel'; String toString() => '$hourOfPeriodLabel:$minuteLabel $periodLabel';
......
...@@ -18,4 +18,6 @@ export 'dart:ui' show ...@@ -18,4 +18,6 @@ export 'dart:ui' show
TextBaseline, TextBaseline,
TextDecoration, TextDecoration,
TextDecorationStyle, TextDecorationStyle,
VoidCallback; VoidCallback,
hashValues,
hashList;
...@@ -39,12 +39,7 @@ class BorderSide { ...@@ -39,12 +39,7 @@ class BorderSide {
width == typedOther.width; width == typedOther.width;
} }
int get hashCode { int get hashCode => hashValues(color, width);
int value = 373;
value = 37 * value + color.hashCode;
value = 37 * value + width.hashCode;
return value;
}
String toString() => 'BorderSide($color, $width)'; String toString() => 'BorderSide($color, $width)';
} }
...@@ -96,14 +91,7 @@ class Border { ...@@ -96,14 +91,7 @@ class Border {
left == typedOther.left; left == typedOther.left;
} }
int get hashCode { int get hashCode => hashValues(top, right, bottom, left);
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;
}
String toString() => 'Border($top, $right, $bottom, $left)'; String toString() => 'Border($top, $right, $bottom, $left)';
} }
...@@ -199,14 +187,7 @@ class BoxShadow { ...@@ -199,14 +187,7 @@ class BoxShadow {
spreadRadius == typedOther.spreadRadius; spreadRadius == typedOther.spreadRadius;
} }
int get hashCode { int get hashCode => hashValues(color, offset, blurRadius, spreadRadius);
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;
}
String toString() => 'BoxShadow($color, $offset, $blurRadius, $spreadRadius)'; String toString() => 'BoxShadow($color, $offset, $blurRadius, $spreadRadius)';
} }
...@@ -282,25 +263,7 @@ class LinearGradient extends Gradient { ...@@ -282,25 +263,7 @@ class LinearGradient extends Gradient {
return true; return true;
} }
int get hashCode { int get hashCode => hashValues(begin, end, tileMode, hashList(colors), hashList(stops));
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;
}
String toString() { String toString() {
return 'LinearGradient($begin, $end, $colors, $stops, $tileMode)'; return 'LinearGradient($begin, $end, $colors, $stops, $tileMode)';
...@@ -374,25 +337,7 @@ class RadialGradient extends Gradient { ...@@ -374,25 +337,7 @@ class RadialGradient extends Gradient {
return true; return true;
} }
int get hashCode { int get hashCode => hashValues(center, radius, tileMode, hashList(colors), hashList(stops));
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;
}
String toString() { String toString() {
return 'RadialGradient($center, $radius, $colors, $stops, $tileMode)'; return 'RadialGradient($center, $radius, $colors, $stops, $tileMode)';
...@@ -582,12 +527,7 @@ class FractionalOffset { ...@@ -582,12 +527,7 @@ class FractionalOffset {
return x == typedOther.x && return x == typedOther.x &&
y == typedOther.y; y == typedOther.y;
} }
int get hashCode { int get hashCode => hashValues(x, y);
int value = 373;
value = 37 * value + x.hashCode;
value = 37 * value + y.hashCode;
return value;
}
static FractionalOffset lerp(FractionalOffset a, FractionalOffset b, double t) { static FractionalOffset lerp(FractionalOffset a, FractionalOffset b, double t) {
if (a == null && b == null) if (a == null && b == null)
return null; return null;
...@@ -688,16 +628,7 @@ class BackgroundImage { ...@@ -688,16 +628,7 @@ class BackgroundImage {
_imageResource == typedOther._imageResource; _imageResource == typedOther._imageResource;
} }
int get hashCode { int get hashCode => hashValues(fit, repeat, centerSlice, colorFilter, alignment, _imageResource);
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;
}
String toString() => 'BackgroundImage($fit, $repeat)'; String toString() => 'BackgroundImage($fit, $repeat)';
} }
...@@ -850,15 +781,15 @@ class BoxDecoration extends Decoration { ...@@ -850,15 +781,15 @@ class BoxDecoration extends Decoration {
} }
int get hashCode { int get hashCode {
int value = 373; return hashValues(
value = 37 * value + backgroundColor.hashCode; backgroundColor,
value = 37 * value + backgroundImage.hashCode; backgroundImage,
value = 37 * value + border.hashCode; border,
value = 37 * value + borderRadius.hashCode; borderRadius,
value = 37 * value + boxShadow.hashCode; boxShadow,
value = 37 * value + gradient.hashCode; gradient,
value = 37 * value + shape.hashCode; shape
return value; );
} }
String toString([String prefix = '']) { String toString([String prefix = '']) {
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
import 'dart:ui' show Color, lerpDouble; import 'dart:ui' show Color, lerpDouble, hashValues;
class HSVColor { class HSVColor {
const HSVColor.fromAHSV(this.alpha, this.hue, this.saturation, this.value); const HSVColor.fromAHSV(this.alpha, this.hue, this.saturation, this.value);
...@@ -113,14 +113,7 @@ class HSVColor { ...@@ -113,14 +113,7 @@ class HSVColor {
&& typedOther.value == value; && typedOther.value == value;
} }
int get hashCode { int get hashCode => hashValues(alpha, hue, saturation, value);
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;
}
String toString() => "HSVColor($alpha, $hue, $saturation, $value)"; String toString() => "HSVColor($alpha, $hue, $saturation, $value)";
} }
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
// found in the LICENSE file. // found in the LICENSE file.
import 'dart:ui' as ui; import 'dart:ui' as ui;
import 'dart:ui' show hashValues;
/// An immutable set of offsets in each of the four cardinal directions. /// An immutable set of offsets in each of the four cardinal directions.
/// ///
...@@ -136,14 +137,7 @@ class EdgeDims { ...@@ -136,14 +137,7 @@ class EdgeDims {
left == typedOther.left; left == typedOther.left;
} }
int get hashCode { int get hashCode => hashValues(top, left, bottom, right);
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;
}
String toString() => "EdgeDims($top, $right, $bottom, $left)"; String toString() => "EdgeDims($top, $right, $bottom, $left)";
} }
...@@ -78,13 +78,7 @@ class StyledTextSpan extends TextSpan { ...@@ -78,13 +78,7 @@ class StyledTextSpan extends TextSpan {
return true; return true;
} }
int get hashCode { int get hashCode => hashValues(style, hashList(children));
int value = 373;
value = 37 * value + style.hashCode;
for (TextSpan child in children)
value = 37 * value + child.hashCode;
return value;
}
String toString([String prefix = '']) { String toString([String prefix = '']) {
List<String> result = <String>[]; List<String> result = <String>[];
......
...@@ -163,21 +163,20 @@ class TextStyle { ...@@ -163,21 +163,20 @@ class TextStyle {
} }
int get hashCode { int get hashCode {
// Use Quiver: https://github.com/domokit/mojo/issues/236 return hashValues(
int value = 373; super.hashCode,
value = 37 * value + inherit.hashCode; color,
value = 37 * value + color.hashCode; fontFamily,
value = 37 * value + fontFamily.hashCode; fontSize,
value = 37 * value + fontSize.hashCode; fontWeight,
value = 37 * value + fontWeight.hashCode; fontStyle,
value = 37 * value + fontStyle.hashCode; letterSpacing,
value = 37 * value + letterSpacing.hashCode; textAlign,
value = 37 * value + textAlign.hashCode; textBaseline,
value = 37 * value + textBaseline.hashCode; decoration,
value = 37 * value + decoration.hashCode; decorationColor,
value = 37 * value + decorationColor.hashCode; decorationStyle
value = 37 * value + decorationStyle.hashCode; );
return value;
} }
String toString([String prefix = '']) { String toString([String prefix = '']) {
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
import 'dart:math' as math; import 'dart:math' as math;
import 'dart:ui' as ui; import 'dart:ui' as ui;
import 'dart:ui' show hashValues;
import 'package:flutter/animation.dart'; import 'package:flutter/animation.dart';
import 'package:flutter/gestures.dart'; import 'package:flutter/gestures.dart';
...@@ -272,12 +273,7 @@ class BoxConstraints extends Constraints { ...@@ -272,12 +273,7 @@ class BoxConstraints extends Constraints {
int get hashCode { int get hashCode {
assert(isNormalized); assert(isNormalized);
int value = 373; return hashValues(minWidth, maxWidth, minHeight, maxHeight);
value = 37 * value + minWidth.hashCode;
value = 37 * value + maxWidth.hashCode;
value = 37 * value + minHeight.hashCode;
value = 37 * value + maxHeight.hashCode;
return value;
} }
String toString() { String toString() {
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
// found in the LICENSE file. // found in the LICENSE file.
import 'dart:math' as math; import 'dart:math' as math;
import 'dart:ui' show lerpDouble; import 'dart:ui' show lerpDouble, hashValues;
import 'box.dart'; import 'box.dart';
import 'object.dart'; import 'object.dart';
...@@ -123,14 +123,7 @@ class RelativeRect { ...@@ -123,14 +123,7 @@ class RelativeRect {
bottom == typedOther.bottom; bottom == typedOther.bottom;
} }
int get hashCode { int get hashCode => hashValues(left, top, right, bottom);
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;
}
String toString() => "RelativeRect.fromLTRB(${left.toStringAsFixed(1)}, ${top.toStringAsFixed(1)}, ${right.toStringAsFixed(1)}, ${bottom.toStringAsFixed(1)})"; String toString() => "RelativeRect.fromLTRB(${left.toStringAsFixed(1)}, ${top.toStringAsFixed(1)}, ${right.toStringAsFixed(1)}, ${bottom.toStringAsFixed(1)})";
} }
......
...@@ -7,6 +7,7 @@ import 'dart:collection'; ...@@ -7,6 +7,7 @@ import 'dart:collection';
import 'package:flutter/rendering.dart'; import 'package:flutter/rendering.dart';
export 'dart:ui' show hashValues, hashList;
export 'package:flutter/rendering.dart' show debugPrint; export 'package:flutter/rendering.dart' show debugPrint;
// KEYS // KEYS
......
...@@ -63,7 +63,7 @@ class _ChildKey { ...@@ -63,7 +63,7 @@ class _ChildKey {
return type == typedOther.type && return type == typedOther.type &&
key == typedOther.key; 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)"; String toString() => "_ChildKey(type: $type, key: $key)";
} }
......
...@@ -30,16 +30,7 @@ class _StorageEntryIdentifier { ...@@ -30,16 +30,7 @@ class _StorageEntryIdentifier {
} }
return true; return true;
} }
int get hashCode { int get hashCode => hashValues(clientType, scopeKey, hashList(keys));
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;
}
} }
class PageStorageBucket { 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