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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 if (length == 0) return []; | 67 if (length == 0) return []; |
68 Arrays.rangeCheck(this, start, length); | 68 Arrays.rangeCheck(this, start, length); |
69 List list = new _GrowableObjectArray<T>.withCapacity(length); | 69 List list = new _GrowableObjectArray<T>.withCapacity(length); |
70 list.length = length; | 70 list.length = length; |
71 Arrays.copy(this, start, list, 0, length); | 71 Arrays.copy(this, start, list, 0, length); |
72 return list; | 72 return list; |
73 } | 73 } |
74 | 74 |
75 factory _GrowableObjectArray(int length) { | 75 factory _GrowableObjectArray(int length) { |
76 var data = new _ObjectArray<T>((length == 0) ? 4 : length); | 76 var data = new _ObjectArray<T>((length == 0) ? 4 : length); |
77 var result = new _GrowableObjectArray<T>.fromObjectArray(data); | 77 var result = new _GrowableObjectArray<T>.withData(data); |
78 result._setLength(length); | 78 result._setLength(length); |
79 return result; | 79 return result; |
80 } | 80 } |
81 | 81 |
82 factory _GrowableObjectArray.withCapacity(int capacity) { | 82 factory _GrowableObjectArray.withCapacity(int capacity) { |
83 var data = new _ObjectArray<T>((capacity == 0)? 4 : capacity); | 83 var data = new _ObjectArray<T>((capacity == 0)? 4 : capacity); |
84 return new _GrowableObjectArray<T>.fromObjectArray(data); | 84 return new _GrowableObjectArray<T>.withData(data); |
85 } | 85 } |
86 | 86 |
87 factory _GrowableObjectArray.from(Collection<T> other) { | 87 factory _GrowableObjectArray.from(Collection<T> other) { |
88 List<T> result = new _GrowableObjectArray<T>(); | 88 List<T> result = new _GrowableObjectArray<T>(); |
89 result.addAll(other); | 89 result.addAll(other); |
90 return result; | 90 return result; |
91 } | 91 } |
92 | 92 |
93 factory _GrowableObjectArray.fromObjectArray(_ObjectArray<T> data) | 93 factory _GrowableObjectArray.withData(_ObjectArray<T> data) |
94 native "GrowableObjectArray_allocate"; | 94 native "GrowableObjectArray_allocate"; |
95 | 95 |
96 int get length native "GrowableObjectArray_getLength"; | 96 int get length native "GrowableObjectArray_getLength"; |
97 | 97 |
98 int get _capacity native "GrowableObjectArray_getCapacity"; | 98 int get _capacity native "GrowableObjectArray_getCapacity"; |
99 | 99 |
100 void set length(int new_length) { | 100 void set length(int new_length) { |
101 if (new_length > _capacity) { | 101 if (new_length > _capacity) { |
102 _grow(new_length); | 102 _grow(new_length); |
103 } else { | 103 } else { |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
290 } | 290 } |
291 | 291 |
292 List<T> toList() { | 292 List<T> toList() { |
293 return new List<T>.from(this); | 293 return new List<T>.from(this); |
294 } | 294 } |
295 | 295 |
296 Set<T> toSet() { | 296 Set<T> toSet() { |
297 return new Set<T>.from(this); | 297 return new Set<T>.from(this); |
298 } | 298 } |
299 } | 299 } |
OLD | NEW |