|
2 | 2 | // for details. All rights reserved. Use of this source code is governed by a |
3 | 3 | // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
|
5 | | -import 'dart:collection'; |
6 | | - |
7 | 5 | import 'package:collection/collection.dart'; |
8 | 6 | import '../ir/ir.dart' as ir; |
9 | 7 | import 'builder.dart'; |
@@ -130,22 +128,16 @@ class _RecGroupBuilder { |
130 | 128 | // (1) group length |
131 | 129 | // (2) length of first struct |
132 | 130 | // (3) group structural equality |
133 | | - final equivalenceGroups = |
134 | | - LinkedHashMap<(int, int, List<ir.DefType>), List<List<ir.DefType>>>( |
135 | | - hashCode: (a) => Object.hash(a.$1, a.$2), |
136 | | - equals: (a, b) => |
137 | | - a.$1 == b.$1 && |
138 | | - a.$2 == b.$2 && |
139 | | - _areGroupsStructurallyEqual(a.$3, b.$3), |
140 | | - ); |
| 131 | + final equivalenceGroups = <_RecursionGroupKey, List<List<ir.DefType>>>{}; |
141 | 132 |
|
142 | 133 | for (final group in groups) { |
143 | 134 | final structIndex = group.indexWhere((g) => g is ir.StructType); |
144 | 135 | // Skip groups with no struct types. |
145 | 136 | if (structIndex == -1) continue; |
146 | 137 | final structType = group[structIndex] as ir.StructType; |
147 | | - equivalenceGroups.putIfAbsent( |
148 | | - (group.length, structType.fields.length, group), () => []).add(group); |
| 138 | + final key = |
| 139 | + _RecursionGroupKey(group.length, structType.fields.length, group); |
| 140 | + equivalenceGroups.putIfAbsent(key, () => []).add(group); |
149 | 141 | } |
150 | 142 |
|
151 | 143 | for (final equalGroups in equivalenceGroups.values) { |
@@ -351,3 +343,22 @@ class _FunctionTypeKey { |
351 | 343 | return (inputHash * 2 + 1) * (outputHash * 2 + 1); |
352 | 344 | } |
353 | 345 | } |
| 346 | + |
| 347 | +class _RecursionGroupKey { |
| 348 | + final int groupLength; |
| 349 | + final int lengthOfFirstStruct; |
| 350 | + final List<ir.DefType> types; |
| 351 | + |
| 352 | + _RecursionGroupKey(this.groupLength, this.lengthOfFirstStruct, this.types); |
| 353 | + |
| 354 | + @override |
| 355 | + int get hashCode => Object.hash(groupLength, lengthOfFirstStruct); |
| 356 | + |
| 357 | + @override |
| 358 | + bool operator ==(other) { |
| 359 | + if (other is! _RecursionGroupKey) return false; |
| 360 | + if (groupLength != other.groupLength) return false; |
| 361 | + if (lengthOfFirstStruct != other.lengthOfFirstStruct) return false; |
| 362 | + return _RecGroupBuilder._areGroupsStructurallyEqual(types, other.types); |
| 363 | + } |
| 364 | +} |
0 commit comments