| 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 _MapletMarker _MARKER = const _MapletMarker(); | 10 static const _MapletMarker _MARKER = const _MapletMarker(); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 int get length { | 47 int get length { |
| 48 if (_extra == null) { | 48 if (_extra == null) { |
| 49 return (_MARKER == _key) ? 0 : 1; | 49 return (_MARKER == _key) ? 0 : 1; |
| 50 } else if (_MARKER == _extra) { | 50 } else if (_MARKER == _extra) { |
| 51 return _key.length; | 51 return _key.length; |
| 52 } else { | 52 } else { |
| 53 return _extra; | 53 return _extra; |
| 54 } | 54 } |
| 55 } | 55 } |
| 56 | 56 |
| 57 bool containsKey(K key) { | 57 bool containsKey(Object key) { |
| 58 if (_extra == null) { | 58 if (_extra == null) { |
| 59 return _key == key; | 59 return _key == key; |
| 60 } else if (_MARKER == _extra) { | 60 } else if (_MARKER == _extra) { |
| 61 return _key.containsKey(key); | 61 return _key.containsKey(key); |
| 62 } else { | 62 } else { |
| 63 for (int remaining = _extra, i = 0; remaining > 0 && i < CAPACITY; i++) { | 63 for (int remaining = _extra, i = 0; remaining > 0 && i < CAPACITY; i++) { |
| 64 var candidate = _key[i]; | 64 var candidate = _key[i]; |
| 65 if (_MARKER == candidate) continue; | 65 if (_MARKER == candidate) continue; |
| 66 if (candidate == key) return true; | 66 if (candidate == key) return true; |
| 67 remaining--; | 67 remaining--; |
| 68 } | 68 } |
| 69 return false; | 69 return false; |
| 70 } | 70 } |
| 71 } | 71 } |
| 72 | 72 |
| 73 V operator [](K key) { | 73 V operator [](Object key) { |
| 74 if (_extra == null) { | 74 if (_extra == null) { |
| 75 return (_key == key) ? _value : null; | 75 return (_key == key) ? _value : null; |
| 76 } else if (_MARKER == _extra) { | 76 } else if (_MARKER == _extra) { |
| 77 return _key[key]; | 77 return _key[key]; |
| 78 } else { | 78 } else { |
| 79 for (int remaining = _extra, i = 0; remaining > 0 && i < CAPACITY; i++) { | 79 for (int remaining = _extra, i = 0; remaining > 0 && i < CAPACITY; i++) { |
| 80 var candidate = _key[i]; | 80 var candidate = _key[i]; |
| 81 if (_MARKER == candidate) continue; | 81 if (_MARKER == candidate) continue; |
| 82 if (candidate == key) return _key[i + CAPACITY]; | 82 if (candidate == key) return _key[i + CAPACITY]; |
| 83 remaining--; | 83 remaining--; |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 } else { | 159 } else { |
| 160 Map map = new Map(); | 160 Map map = new Map(); |
| 161 forEach((eachKey, eachValue) => map[eachKey] = eachValue); | 161 forEach((eachKey, eachValue) => map[eachKey] = eachValue); |
| 162 map[key] = value; | 162 map[key] = value; |
| 163 _key = map; | 163 _key = map; |
| 164 _extra = _MARKER; | 164 _extra = _MARKER; |
| 165 } | 165 } |
| 166 } | 166 } |
| 167 } | 167 } |
| 168 | 168 |
| 169 V remove(K key) { | 169 V remove(Object key) { |
| 170 if (_extra == null) { | 170 if (_extra == null) { |
| 171 if (_key != key) return null; | 171 if (_key != key) return null; |
| 172 _key = _MARKER; | 172 _key = _MARKER; |
| 173 V result = _value; | 173 V result = _value; |
| 174 _value = null; | 174 _value = null; |
| 175 return result; | 175 return result; |
| 176 } else if (_MARKER == _extra) { | 176 } else if (_MARKER == _extra) { |
| 177 return _key.remove(key); | 177 return _key.remove(key); |
| 178 } else { | 178 } else { |
| 179 for (int remaining = _extra, i = 0; remaining > 0 && i < CAPACITY; i++) { | 179 for (int remaining = _extra, i = 0; remaining > 0 && i < CAPACITY; i++) { |
| (...skipping 91 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 |