OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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.util.maplet; | 5 library dart2js.util.maplet; |
6 | 6 |
7 import 'dart:collection' show MapBase, IterableBase; | 7 import 'dart:collection' show MapBase, IterableBase; |
8 | 8 |
9 class Maplet<K, V> extends MapBase<K, V> { | 9 class Maplet<K, V> extends MapBase<K, V> { |
10 static const _MARKER = const _MapletMarker(); | 10 static const _MapletMarker _MARKER = const _MapletMarker(); |
11 static const CAPACITY = 8; | 11 static const int CAPACITY = 8; |
12 | 12 |
13 // The maplet can be in one of four states: | 13 // The maplet can be in one of four states: |
14 // | 14 // |
15 // * Empty (extra: null, key: marker, value: null) | 15 // * Empty (extra: null, key: marker, value: null) |
16 // * Single element (extra: null, key: key, value: value) | 16 // * Single element (extra: null, key: key, value: value) |
17 // * List-backed (extra: length, key: list, value: null) | 17 // * List-backed (extra: length, key: list, value: null) |
18 // * Map-backed (extra: marker, key: map, value: null) | 18 // * Map-backed (extra: marker, key: map, value: null) |
19 // | 19 // |
20 // When the maplet is list-backed, the list has two sections: One | 20 // When the maplet is list-backed, the list has two sections: One |
21 // for keys and one for values. The first [CAPACITY] entries are | 21 // for keys and one for values. The first [CAPACITY] entries are |
22 // the keys and they may contain markers for deleted elements. After | 22 // the keys and they may contain markers for deleted elements. After |
23 // the keys there are [CAPACITY] entries for the values. | 23 // the keys there are [CAPACITY] entries for the values. |
24 | 24 |
25 var _key = _MARKER; | 25 dynamic _key = _MARKER; |
26 var _value; | 26 var _value; |
27 var _extra; | 27 var _extra; |
28 | 28 |
29 Maplet(); | 29 Maplet(); |
30 | 30 |
31 Maplet.from(Maplet<K, V> other) { | 31 Maplet.from(Maplet<K, V> other) { |
32 other.forEach((K key, V value) { | 32 other.forEach((K key, V value) { |
33 this[key] = value; | 33 this[key] = value; |
34 }); | 34 }); |
35 } | 35 } |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
271 if (Maplet._MARKER != candidate) { | 271 if (Maplet._MARKER != candidate) { |
272 _current = candidate; | 272 _current = candidate; |
273 _remaining--; | 273 _remaining--; |
274 return true; | 274 return true; |
275 } | 275 } |
276 } | 276 } |
277 _current = null; | 277 _current = null; |
278 return false; | 278 return false; |
279 } | 279 } |
280 } | 280 } |
OLD | NEW |