| 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 class _GrowableObjectArray<T> implements List<T> { | 5 class _GrowableObjectArray<T> implements List<T> { |
| 6 factory _GrowableObjectArray._uninstantiable() { | 6 factory _GrowableObjectArray._uninstantiable() { |
| 7 throw new UnsupportedError( | 7 throw new UnsupportedError( |
| 8 "GrowableObjectArray can only be allocated by the VM"); | 8 "GrowableObjectArray can only be allocated by the VM"); |
| 9 } | 9 } |
| 10 | 10 |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 List<T> result = new _GrowableObjectArray<T>(); | 86 List<T> result = new _GrowableObjectArray<T>(); |
| 87 result.addAll(other); | 87 result.addAll(other); |
| 88 return result; | 88 return result; |
| 89 } | 89 } |
| 90 | 90 |
| 91 factory _GrowableObjectArray.fromObjectArray(_ObjectArray<T> data) | 91 factory _GrowableObjectArray.fromObjectArray(_ObjectArray<T> data) |
| 92 native "GrowableObjectArray_allocate"; | 92 native "GrowableObjectArray_allocate"; |
| 93 | 93 |
| 94 int get length native "GrowableObjectArray_getLength"; | 94 int get length native "GrowableObjectArray_getLength"; |
| 95 | 95 |
| 96 int get capacity native "GrowableObjectArray_getCapacity"; | 96 int get _capacity native "GrowableObjectArray_getCapacity"; |
| 97 | 97 |
| 98 void set length(int new_length) { | 98 void set length(int new_length) { |
| 99 if (new_length > capacity) { | 99 if (new_length > _capacity) { |
| 100 _grow(new_length); | 100 _grow(new_length); |
| 101 } else { | 101 } else { |
| 102 for (int i = new_length; i < length; i++) { | 102 for (int i = new_length; i < length; i++) { |
| 103 this[i] = null; | 103 this[i] = null; |
| 104 } | 104 } |
| 105 } | 105 } |
| 106 _setLength(new_length); | 106 _setLength(new_length); |
| 107 } | 107 } |
| 108 | 108 |
| 109 void _setLength(int new_length) native "GrowableObjectArray_setLength"; | 109 void _setLength(int new_length) native "GrowableObjectArray_setLength"; |
| 110 | 110 |
| 111 void _setData(_ObjectArray<T> array) native "GrowableObjectArray_setData"; | 111 void _setData(_ObjectArray<T> array) native "GrowableObjectArray_setData"; |
| 112 | 112 |
| 113 T operator [](int index) native "GrowableObjectArray_getIndexed"; | 113 T operator [](int index) native "GrowableObjectArray_getIndexed"; |
| 114 | 114 |
| 115 void operator []=(int index, T value) native "GrowableObjectArray_setIndexed"; | 115 void operator []=(int index, T value) native "GrowableObjectArray_setIndexed"; |
| 116 | 116 |
| 117 // The length of this growable array. It is always less than or equal to the | 117 // The length of this growable array. It is always less than or equal to the |
| 118 // length of the object array, which itself is always greater than 0, so that | 118 // length of the object array, which itself is always greater than 0, so that |
| 119 // grow() does not have to check for a zero length object array before | 119 // grow() does not have to check for a zero length object array before |
| 120 // doubling its size. | 120 // doubling its size. |
| 121 void add(T value) { | 121 void add(T value) { |
| 122 var len = length; | 122 var len = length; |
| 123 if (len == capacity) { | 123 if (len == _capacity) { |
| 124 _grow(len * 2); | 124 _grow(len * 2); |
| 125 } | 125 } |
| 126 _setLength(len + 1); | 126 _setLength(len + 1); |
| 127 this[len] = value; | 127 this[len] = value; |
| 128 } | 128 } |
| 129 | 129 |
| 130 void addLast(T element) { | 130 void addLast(T element) { |
| 131 add(element); | 131 add(element); |
| 132 } | 132 } |
| 133 | 133 |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 } | 217 } |
| 218 | 218 |
| 219 String toString() { | 219 String toString() { |
| 220 return Collections.collectionToString(this); | 220 return Collections.collectionToString(this); |
| 221 } | 221 } |
| 222 | 222 |
| 223 Iterator<T> iterator() { | 223 Iterator<T> iterator() { |
| 224 return new SequenceIterator<T>(this); | 224 return new SequenceIterator<T>(this); |
| 225 } | 225 } |
| 226 } | 226 } |
| OLD | NEW |