Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(115)

Side by Side Diff: runtime/lib/growable_array.dart

Issue 14265015: Do not set growable array length unnecessarily. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | runtime/vm/flow_graph_builder.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 if (start == end) return <T>[]; 121 if (start == end) return <T>[];
122 List list = new _GrowableObjectArray<T>.withCapacity(length); 122 List list = new _GrowableObjectArray<T>.withCapacity(length);
123 list.length = length; 123 list.length = length;
124 Arrays.copy(this, start, list, 0, length); 124 Arrays.copy(this, start, list, 0, length);
125 return list; 125 return list;
126 } 126 }
127 127
128 factory _GrowableObjectArray(int length) { 128 factory _GrowableObjectArray(int length) {
129 var data = new _ObjectArray((length == 0) ? 4 : length); 129 var data = new _ObjectArray((length == 0) ? 4 : length);
130 var result = new _GrowableObjectArray<T>.withData(data); 130 var result = new _GrowableObjectArray<T>.withData(data);
131 result._setLength(length); 131 if (length > 0) {
132 result._setLength(length);
133 }
132 return result; 134 return result;
133 } 135 }
134 136
135 factory _GrowableObjectArray.withCapacity(int capacity) { 137 factory _GrowableObjectArray.withCapacity(int capacity) {
136 var data = new _ObjectArray((capacity == 0)? 4 : capacity); 138 var data = new _ObjectArray((capacity == 0)? 4 : capacity);
137 return new _GrowableObjectArray<T>.withData(data); 139 return new _GrowableObjectArray<T>.withData(data);
138 } 140 }
139 141
140 factory _GrowableObjectArray.from(Iterable<T> other) { 142 factory _GrowableObjectArray.from(Iterable<T> other) {
141 List<T> result = new _GrowableObjectArray<T>(); 143 List<T> result = new _GrowableObjectArray<T>();
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
347 } 349 }
348 350
349 Set<T> toSet() { 351 Set<T> toSet() {
350 return new Set<T>.from(this); 352 return new Set<T>.from(this);
351 } 353 }
352 354
353 Map<int, T> asMap() { 355 Map<int, T> asMap() {
354 return IterableMixinWorkaround.asMapList(this); 356 return IterableMixinWorkaround.asMapList(this);
355 } 357 }
356 } 358 }
OLDNEW
« no previous file with comments | « no previous file | runtime/vm/flow_graph_builder.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698