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

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

Issue 11773045: Factor out length check in list factories: reduce bloat, factorize code, improve performance. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 11 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 | « runtime/lib/array_patch.dart ('k') | no next file » | 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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 65
66 List<T> getRange(int start, int length) { 66 List<T> getRange(int start, int length) {
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() { 75 factory _GrowableObjectArray(int length) {
76 var data = new _ObjectArray<T>(4); 76 var data = new _ObjectArray<T>((length == 0) ? 4 : length);
77 return new _GrowableObjectArray<T>.fromObjectArray(data); 77 var result = new _GrowableObjectArray<T>.fromObjectArray(data);
78 result._setLength(length);
79 return result;
78 } 80 }
79 81
80 factory _GrowableObjectArray.withCapacity(int capacity) { 82 factory _GrowableObjectArray.withCapacity(int capacity) {
81 var data = new _ObjectArray<T>((capacity == 0)? 4 : capacity); 83 var data = new _ObjectArray<T>((capacity == 0)? 4 : capacity);
82 return new _GrowableObjectArray<T>.fromObjectArray(data); 84 return new _GrowableObjectArray<T>.fromObjectArray(data);
83 } 85 }
84 86
85 factory _GrowableObjectArray.from(Collection<T> other) { 87 factory _GrowableObjectArray.from(Collection<T> other) {
86 List<T> result = new _GrowableObjectArray<T>(); 88 List<T> result = new _GrowableObjectArray<T>();
87 result.addAll(other); 89 result.addAll(other);
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 } 290 }
289 291
290 List<T> toList() { 292 List<T> toList() {
291 return new List<T>.from(this); 293 return new List<T>.from(this);
292 } 294 }
293 295
294 Set<T> toSet() { 296 Set<T> toSet() {
295 return new Set<T>.from(this); 297 return new Set<T>.from(this);
296 } 298 }
297 } 299 }
OLDNEW
« no previous file with comments | « runtime/lib/array_patch.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698