提交 49a8dfb3 编写于 作者: I Ian Hickson

Merge pull request #2165 from Hixie/hashCodes

Provide an API for hashCode getters.
......@@ -258,9 +258,10 @@ core_idl_files = get_path_info([
"abspath")
core_dart_files = get_path_info([
"dart/hash_codes.dart",
"dart/hooks.dart",
"dart/natives.dart",
"dart/lerp.dart",
"dart/natives.dart",
"dart/painting.dart",
"dart/text.dart",
"dart/window.dart",
......@@ -276,9 +277,9 @@ core_dart_files = get_path_info([
"painting/Paint.dart",
"painting/PaintingStyle.dart",
"painting/Point.dart",
"painting/Rect.dart",
"painting/RRect.dart",
"painting/RSTransform.dart",
"painting/Rect.dart",
"painting/Size.dart",
"painting/TransferMode.dart",
"painting/VertexMode.dart",
......
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
part of dart_ui;
class _HashEnd { const _HashEnd(); }
const _HashEnd _hashEnd = const _HashEnd();
/// Combine up to twenty values' hashCodes into one value.
///
/// If you only need to handle one value's hashCode, then just refer to its
/// [hashCode] getter directly.
///
/// If you need to combine an arbitrary number of values from a List or other
/// Iterable, use [hashList]. The output of hashList can be used as one of the
/// arguments to this function.
///
/// For example:
///
/// int hashCode => hashValues(foo, bar, hashList(quux), baz);
int hashValues(
Object arg01, Object arg02, [ Object arg03 = _hashEnd,
Object arg04 = _hashEnd, Object arg05 = _hashEnd, Object arg06 = _hashEnd,
Object arg07 = _hashEnd, Object arg08 = _hashEnd, Object arg09 = _hashEnd,
Object arg10 = _hashEnd, Object arg11 = _hashEnd, Object arg12 = _hashEnd,
Object arg13 = _hashEnd, Object arg14 = _hashEnd, Object arg15 = _hashEnd,
Object arg16 = _hashEnd, Object arg17 = _hashEnd, Object arg18 = _hashEnd,
Object arg19 = _hashEnd, Object arg20 = _hashEnd ]) {
int result = 373;
assert(arg01 is! Iterable);
result = 37 * result + arg01.hashCode;
assert(arg02 is! Iterable);
result = 37 * result + arg02.hashCode;
if (arg03 != _hashEnd) {
assert(arg03 is! Iterable);
result = 37 * result + arg03.hashCode;
if (arg04 != _hashEnd) {
assert(arg04 is! Iterable);
result = 37 * result + arg04.hashCode;
if (arg05 != _hashEnd) {
assert(arg05 is! Iterable);
result = 37 * result + arg05.hashCode;
if (arg06 != _hashEnd) {
assert(arg06 is! Iterable);
result = 37 * result + arg06.hashCode;
if (arg07 != _hashEnd) {
assert(arg07 is! Iterable);
result = 37 * result + arg07.hashCode;
if (arg08 != _hashEnd) {
assert(arg08 is! Iterable);
result = 37 * result + arg08.hashCode;
if (arg09 != _hashEnd) {
assert(arg09 is! Iterable);
result = 37 * result + arg09.hashCode;
if (arg10 != _hashEnd) {
assert(arg10 is! Iterable);
result = 37 * result + arg10.hashCode;
if (arg11 != _hashEnd) {
assert(arg11 is! Iterable);
result = 37 * result + arg11.hashCode;
if (arg12 != _hashEnd) {
assert(arg12 is! Iterable);
result = 37 * result + arg12.hashCode;
if (arg13 != _hashEnd) {
assert(arg13 is! Iterable);
result = 37 * result + arg13.hashCode;
if (arg14 != _hashEnd) {
assert(arg14 is! Iterable);
result = 37 * result + arg14.hashCode;
if (arg15 != _hashEnd) {
assert(arg15 is! Iterable);
result = 37 * result + arg15.hashCode;
if (arg16 != _hashEnd) {
assert(arg16 is! Iterable);
result = 37 * result + arg16.hashCode;
if (arg17 != _hashEnd) {
assert(arg17 is! Iterable);
result = 37 * result + arg17.hashCode;
if (arg18 != _hashEnd) {
assert(arg18 is! Iterable);
result = 37 * result + arg18.hashCode;
if (arg19 != _hashEnd) {
assert(arg19 is! Iterable);
result = 37 * result + arg19.hashCode;
if (arg20 != _hashEnd) {
assert(arg20 is! Iterable);
result = 37 * result + arg20.hashCode;
// I can see my house from here!
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
return result;
}
/// Combine the hashCodes of an arbitrary number of values from an Iterable into
/// one value. This function will return the same value if given "null" as if
/// given an empty list.
int hashList(Iterable<Object> args) {
int result = 373;
if (args != null) {
for (Object arg in args) {
assert(arg is! Iterable);
result = 37 * result + arg.hashCode;
}
}
return result;
}
......@@ -25,10 +25,5 @@ abstract class OffsetBase {
_dy == typedOther._dy;
}
int get hashCode {
int result = 373;
result = 37 * result + _dx.hashCode;
result = 37 * result + _dy.hashCode;
return result;
}
int get hashCode => hashValues(_dx, _dy);
}
......@@ -47,12 +47,7 @@ class Point {
y == typedOther.y;
}
int get hashCode {
int result = 373;
result = 37 * result + x.hashCode;
result = 37 * result + y.hashCode;
return result;
}
int get hashCode => hashValues(x, y);
String toString() => "Point(${x.toStringAsFixed(1)}, ${y.toStringAsFixed(1)})";
}
......@@ -229,7 +229,7 @@ class RRect {
return true;
}
int get hashCode => _value.fold(373, (value, item) => (37 * value + item.hashCode));
int get hashCode => hashList(_value);
String toString() => "RRect.fromLTRBXY(${left.toStringAsFixed(1)}, ${top.toStringAsFixed(1)}, ${right.toStringAsFixed(1)}, ${bottom.toStringAsFixed(1)}, ${radiusX.toStringAsFixed(1)}, ${radiusY.toStringAsFixed(1)})";
}
......@@ -143,7 +143,7 @@ class Rect {
return true;
}
int get hashCode => _value.fold(373, (value, item) => (37 * value + item.hashCode));
int get hashCode => hashList(_value);
String toString() => "Rect.fromLTRB(${left.toStringAsFixed(1)}, ${top.toStringAsFixed(1)}, ${right.toStringAsFixed(1)}, ${bottom.toStringAsFixed(1)})";
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册