| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 patch class Expando<T> { | 5 patch class Expando<T> { |
| 6 /* patch */ Expando([this.name]) | 6 /* patch */ Expando([this.name]) |
| 7 : _data = new List(_minSize), | 7 : _data = new List(_minSize), |
| 8 _used = 0; | 8 _used = 0; |
| 9 | 9 |
| 10 static const _minSize = 8; | 10 static const _minSize = 8; |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 } | 107 } |
| 108 new_size = (new_size < _minSize) ? _minSize : new_size; | 108 new_size = (new_size < _minSize) ? _minSize : new_size; |
| 109 | 109 |
| 110 // Reset the mappings to empty so that we can just add the existing | 110 // Reset the mappings to empty so that we can just add the existing |
| 111 // valid entries. | 111 // valid entries. |
| 112 _data = new List(new_size); | 112 _data = new List(new_size); |
| 113 _used = 0; | 113 _used = 0; |
| 114 | 114 |
| 115 for (var i = 0; i < old_data.length; i++) { | 115 for (var i = 0; i < old_data.length; i++) { |
| 116 var entry = old_data[i]; | 116 var entry = old_data[i]; |
| 117 if ((entry != null) && (entry.key != null)) { | 117 if (entry != null) { |
| 118 this[entry.key] = entry.value; | 118 // Ensure that the entry.key is not cleared between checking for it and |
| 119 // inserting it into the new table. |
| 120 var val = entry.value; |
| 121 var key = entry.key; |
| 122 if (key != null) { |
| 123 this[key] = val; |
| 124 } |
| 119 } | 125 } |
| 120 } | 126 } |
| 121 } | 127 } |
| 122 | 128 |
| 123 static _checkType(object) { | 129 static _checkType(object) { |
| 124 if ((object == null) || | 130 if ((object == null) || |
| 125 (object is bool) || | 131 (object is bool) || |
| 126 (object is num) || | 132 (object is num) || |
| 127 (object is String)) { | 133 (object is String)) { |
| 128 throw new ArgumentError(object); | 134 throw new ArgumentError(object); |
| 129 } | 135 } |
| 130 } | 136 } |
| 131 | 137 |
| 132 get _size => _data.length; | 138 get _size => _data.length; |
| 133 get _limit => (3 * (_size ~/ 4)); | 139 get _limit => (3 * (_size ~/ 4)); |
| 134 | 140 |
| 135 List _data; | 141 List _data; |
| 136 int _used; // Number of used (active and deleted) slots. | 142 int _used; // Number of used (active and deleted) slots. |
| 137 } | 143 } |
| OLD | NEW |