OLD | NEW |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 library dart2js.serialization_test_helper; | 5 library dart2js.serialization_test_helper; |
6 | 6 |
7 import 'dart:collection'; | 7 import 'dart:collection'; |
8 import 'package:compiler/src/common/resolution.dart'; | 8 import 'package:compiler/src/common/resolution.dart'; |
9 import 'package:compiler/src/constants/expressions.dart'; | 9 import 'package:compiler/src/constants/expressions.dart'; |
10 import 'package:compiler/src/constants/values.dart'; | 10 import 'package:compiler/src/constants/values.dart'; |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 Iterable set1, Iterable set2, List<List> common, List unfound, | 201 Iterable set1, Iterable set2, List<List> common, List unfound, |
202 {bool sameElement(a, b): equality, void checkElements(a, b)}) { | 202 {bool sameElement(a, b): equality, void checkElements(a, b)}) { |
203 // TODO(johnniwinther): Avoid the quadratic cost here. Some ideas: | 203 // TODO(johnniwinther): Avoid the quadratic cost here. Some ideas: |
204 // - convert each set to a list and sort it first, then compare by walking | 204 // - convert each set to a list and sort it first, then compare by walking |
205 // both lists in parallel | 205 // both lists in parallel |
206 // - map each element to a canonical object, create a map containing those | 206 // - map each element to a canonical object, create a map containing those |
207 // mappings, use the mapped sets to compare (then operations like | 207 // mappings, use the mapped sets to compare (then operations like |
208 // set.difference would work) | 208 // set.difference would work) |
209 Set remaining = set2.toSet(); | 209 Set remaining = set2.toSet(); |
210 for (var element1 in set1) { | 210 for (var element1 in set1) { |
| 211 bool found = false; |
211 var correspondingElement; | 212 var correspondingElement; |
212 for (var element2 in remaining) { | 213 for (var element2 in remaining) { |
213 if (sameElement(element1, element2)) { | 214 if (sameElement(element1, element2)) { |
214 if (checkElements != null) { | 215 if (checkElements != null) { |
215 checkElements(element1, element2); | 216 checkElements(element1, element2); |
216 } | 217 } |
| 218 found = true; |
217 correspondingElement = element2; | 219 correspondingElement = element2; |
218 remaining.remove(element2); | 220 remaining.remove(element2); |
219 break; | 221 break; |
220 } | 222 } |
221 } | 223 } |
222 if (correspondingElement != null) { | 224 if (found) { |
223 common.add([element1, correspondingElement]); | 225 common.add([element1, correspondingElement]); |
224 } else { | 226 } else { |
225 unfound.add(element1); | 227 unfound.add(element1); |
226 } | 228 } |
227 } | 229 } |
228 return remaining; | 230 return remaining; |
229 } | 231 } |
230 | 232 |
231 /// Check equivalence of the two iterables, [set1] and [set1], as sets using | 233 /// Check equivalence of the two iterables, [set1] and [set1], as sets using |
232 /// [elementEquivalence] to compute the pair-wise equivalence. | 234 /// [elementEquivalence] to compute the pair-wise equivalence. |
(...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
642 } | 644 } |
643 | 645 |
644 if (index == 1 && skip != 0) { | 646 if (index == 1 && skip != 0) { |
645 return ['${skip}', segmentNumber(index)]; | 647 return ['${skip}', segmentNumber(index)]; |
646 } else if (index == count) { | 648 } else if (index == count) { |
647 return [segmentNumber(index - 1)]; | 649 return [segmentNumber(index - 1)]; |
648 } else { | 650 } else { |
649 return [segmentNumber(index - 1), segmentNumber(index)]; | 651 return [segmentNumber(index - 1), segmentNumber(index)]; |
650 } | 652 } |
651 } | 653 } |
OLD | NEW |