| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 part of dart2js.util; | 5 part of dart2js.util; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * The expensive set is a data structure useful for tracking down | 8 * The expensive set is a data structure useful for tracking down |
| 9 * excessive memory usage due to large sets. It acts as an ordinary | 9 * excessive memory usage due to large sets. It acts as an ordinary |
| 10 * hash set, but it uses 10 times more memory (by default). | 10 * hash set, but it uses 10 times more memory (by default). |
| 11 */ | 11 */ |
| 12 class ExpensiveSet<E> extends IterableBase<E> implements LinkedHashSet<E> { | 12 class ExpensiveSet<E> extends IterableBase<E> implements Set<E> { |
| 13 | 13 |
| 14 final List _sets; | 14 final List _sets; |
| 15 | 15 |
| 16 ExpensiveSet([int copies = 10]) : _sets = new List(copies) { | 16 ExpensiveSet([int copies = 10]) : _sets = new List(copies) { |
| 17 assert(copies > 0); | 17 assert(copies > 0); |
| 18 for (int i = 0; i < _sets.length; i++) { | 18 for (int i = 0; i < _sets.length; i++) { |
| 19 _sets[i] = new LinkedHashSet<E>(); | 19 _sets[i] = new Set<E>(); |
| 20 } | 20 } |
| 21 } | 21 } |
| 22 | 22 |
| 23 int get length => _sets[0].length; | 23 int get length => _sets[0].length; |
| 24 bool get isEmpty => _sets[0].isEmpty; | 24 bool get isEmpty => _sets[0].isEmpty; |
| 25 bool get isNotEmpty => _sets[0].isNotEmpty; | 25 bool get isNotEmpty => _sets[0].isNotEmpty; |
| 26 | 26 |
| 27 Iterator<E> get iterator => _sets[0].iterator; | 27 Iterator<E> get iterator => _sets[0].iterator; |
| 28 | 28 |
| 29 bool contains(Object object) => _sets[0].contains(object); | 29 bool contains(Object object) => _sets[0].contains(object); |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 if (objectsToRetain is Set) { | 113 if (objectsToRetain is Set) { |
| 114 retainSet = objectsToRetain; | 114 retainSet = objectsToRetain; |
| 115 } else { | 115 } else { |
| 116 retainSet = objectsToRetain.toSet(); | 116 retainSet = objectsToRetain.toSet(); |
| 117 } | 117 } |
| 118 retainWhere(retainSet.contains); | 118 retainWhere(retainSet.contains); |
| 119 } | 119 } |
| 120 | 120 |
| 121 String toString() => "expensive(${_sets[0]}x${_sets.length})"; | 121 String toString() => "expensive(${_sets[0]}x${_sets.length})"; |
| 122 } | 122 } |
| OLD | NEW |