Skip to content

Commit 9846fa5

Browse files
authored
Audit hashCode overrides outside of packages/flutter (flutter#85370)
1 parent a85811a commit 9846fa5

18 files changed

Lines changed: 30 additions & 68 deletions

File tree

dev/bots/analyze.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,7 @@ class Hash256 {
610610
}
611611

612612
@override
613-
int get hashCode => a ^ b ^ c ^ d;
613+
int get hashCode => Object.hash(a, b, c, d);
614614
}
615615

616616
// DO NOT ADD ANY ENTRIES TO THIS LIST.

dev/devicelab/lib/framework/running_processes.dart

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,7 @@ class RunningProcessInfo {
2828
}
2929

3030
@override
31-
int get hashCode {
32-
// TODO(dnfield): Replace this when Object.hashValues lands, https://github.com/dart-lang/sdk/issues/11617
33-
int hash = 17;
34-
if (pid != null) {
35-
hash = hash * 23 + pid.hashCode;
36-
}
37-
if (commandLine != null) {
38-
hash = hash * 23 + commandLine.hashCode;
39-
}
40-
if (creationDate != null) {
41-
hash = hash * 23 + creationDate.hashCode;
42-
}
43-
return hash;
44-
}
31+
int get hashCode => Object.hash(pid, commandLine, creationDate);
4532

4633
@override
4734
String toString() {

dev/devicelab/test/adb_test.dart

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -166,15 +166,14 @@ class CommandArgs {
166166
}
167167

168168
@override
169-
int get hashCode => 17 * (17 * command.hashCode + _hashArguments) + _hashEnvironment;
170-
171-
int get _hashArguments => arguments != null
172-
? const ListEquality<String>().hash(arguments)
173-
: null.hashCode;
174-
175-
int get _hashEnvironment => environment != null
176-
? const MapEquality<String, String>().hash(environment)
177-
: null.hashCode;
169+
int get hashCode {
170+
return Object.hash(
171+
command,
172+
Object.hashAll(arguments ?? const <String>[]),
173+
Object.hashAllUnordered(environment?.keys ?? const <String>[]),
174+
Object.hashAllUnordered(environment?.values ?? const <String>[]),
175+
);
176+
}
178177
}
179178

180179
class FakeDevice extends AndroidDevice {

dev/integration_tests/android_semantics_testing/lib/src/common.dart

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,7 @@ class Rect {
183183
final double bottom;
184184

185185
@override
186-
int get hashCode =>
187-
top.hashCode ^ left.hashCode ^ right.hashCode ^ bottom.hashCode;
186+
int get hashCode => Object.hash(top, left, right, bottom);
188187

189188
@override
190189
bool operator ==(Object other) {
@@ -216,7 +215,7 @@ class Size {
216215
final double height;
217216

218217
@override
219-
int get hashCode => width.hashCode ^ height.hashCode;
218+
int get hashCode => Object.hash(width, height);
220219

221220
@override
222221
bool operator ==(Object other) {

dev/tools/localization/localizations_utils.dart

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,7 @@ class LocaleInfo implements Comparable<LocaleInfo> {
128128
}
129129

130130
@override
131-
int get hashCode {
132-
return originalString.hashCode;
133-
}
131+
int get hashCode => originalString.hashCode;
134132

135133
@override
136134
String toString() {

dev/tools/vitool/lib/vitool.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ class FrameData {
274274
}
275275

276276
@override
277-
int get hashCode => size.hashCode ^ paths.hashCode;
277+
int get hashCode => Object.hash(size, Object.hashAll(paths));
278278

279279
@override
280280
String toString() {
@@ -328,7 +328,7 @@ class SvgPath {
328328
}
329329

330330
@override
331-
int get hashCode => id.hashCode ^ commands.hashCode ^ opacity.hashCode;
331+
int get hashCode => Object.hash(id, Object.hashAll(commands), opacity);
332332

333333
@override
334334
String toString() {
@@ -377,7 +377,7 @@ class SvgPathCommand {
377377
}
378378

379379
@override
380-
int get hashCode => type.hashCode ^ points.hashCode;
380+
int get hashCode => Object.hash(type, Object.hashAll(points));
381381

382382
@override
383383
String toString() {

packages/flutter/lib/src/material/about.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -798,7 +798,7 @@ class _DetailArguments {
798798
}
799799

800800
@override
801-
int get hashCode => packageName.hashCode; // Good enough.
801+
int get hashCode => hashValues(packageName, hashList(licenseEntries));
802802
}
803803

804804
class _PackageLicensePage extends StatefulWidget {

packages/flutter_driver/lib/src/driver/driver.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -814,5 +814,5 @@ class DriverOffset {
814814
}
815815

816816
@override
817-
int get hashCode => dx.hashCode ^ dy.hashCode;
817+
int get hashCode => Object.hash(dx, dy);
818818
}

packages/flutter_tools/lib/src/asset.dart

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -911,11 +911,7 @@ class _Asset {
911911
}
912912

913913
@override
914-
int get hashCode {
915-
return baseDir.hashCode
916-
^ relativeUri.hashCode
917-
^ entryUri.hashCode;
918-
}
914+
int get hashCode => Object.hash(baseDir, relativeUri, entryUri.hashCode);
919915
}
920916

921917
// Given an assets directory like this:

packages/flutter_tools/lib/src/base/fingerprint.dart

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,7 @@ class Fingerprint {
128128
}
129129

130130
@override
131-
// Ignore map entries here to avoid becoming inconsistent with equals
132-
// due to differences in map entry order. This is a really bad hash
133-
// function and should eventually be deprecated and removed.
134-
int get hashCode => _checksums.length.hashCode;
131+
int get hashCode => Object.hash(Object.hashAllUnordered(_checksums.keys), Object.hashAllUnordered(_checksums.values));
135132

136133
@override
137134
String toString() => '{checksums: $_checksums}';

0 commit comments

Comments
 (0)