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

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

Issue 14065011: Implement getRange (returning an Iterable). (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments. 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 | « runtime/lib/array.dart ('k') | runtime/lib/typeddata.dart » ('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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 62
63 void removeWhere(bool test(T element)) { 63 void removeWhere(bool test(T element)) {
64 IterableMixinWorkaround.removeWhereList(this, test); 64 IterableMixinWorkaround.removeWhereList(this, test);
65 } 65 }
66 66
67 void retainWhere(bool test(T element)) { 67 void retainWhere(bool test(T element)) {
68 IterableMixinWorkaround.removeWhereList(this, 68 IterableMixinWorkaround.removeWhereList(this,
69 (T element) => !test(element)); 69 (T element) => !test(element));
70 } 70 }
71 71
72 Iterable<T> getRange(int start, int end) {
73 return IterableMixinWorkaround.getRangeList(this, start, end);
74 }
75
72 void setRange(int start, int length, List<T> from, [int startFrom = 0]) { 76 void setRange(int start, int length, List<T> from, [int startFrom = 0]) {
73 IterableMixinWorkaround.setRangeList(this, start, length, from, startFrom); 77 IterableMixinWorkaround.setRangeList(this, start, length, from, startFrom);
74 } 78 }
75 79
76 void removeRange(int start, int length) { 80 void removeRange(int start, int length) {
77 if (length == 0) { 81 if (length == 0) {
78 return; 82 return;
79 } 83 }
80 Arrays.rangeCheck(this, start, length); 84 Arrays.rangeCheck(this, start, length);
81 Arrays.copy(this, 85 Arrays.copy(this,
(...skipping 30 matching lines...) Expand all
112 Arrays.indicesCheck(this, start, end); 116 Arrays.indicesCheck(this, start, end);
113 if (end == null) end = length; 117 if (end == null) end = length;
114 int length = end - start; 118 int length = end - start;
115 if (start == end) return <T>[]; 119 if (start == end) return <T>[];
116 List list = new _GrowableObjectArray<T>.withCapacity(length); 120 List list = new _GrowableObjectArray<T>.withCapacity(length);
117 list.length = length; 121 list.length = length;
118 Arrays.copy(this, start, list, 0, length); 122 Arrays.copy(this, start, list, 0, length);
119 return list; 123 return list;
120 } 124 }
121 125
122 List<T> getRange(int start, int length) => sublist(start, start + length);
123
124 factory _GrowableObjectArray(int length) { 126 factory _GrowableObjectArray(int length) {
125 var data = new _ObjectArray((length == 0) ? 4 : length); 127 var data = new _ObjectArray((length == 0) ? 4 : length);
126 var result = new _GrowableObjectArray<T>.withData(data); 128 var result = new _GrowableObjectArray<T>.withData(data);
127 result._setLength(length); 129 result._setLength(length);
128 return result; 130 return result;
129 } 131 }
130 132
131 factory _GrowableObjectArray.withCapacity(int capacity) { 133 factory _GrowableObjectArray.withCapacity(int capacity) {
132 var data = new _ObjectArray((capacity == 0)? 4 : capacity); 134 var data = new _ObjectArray((capacity == 0)? 4 : capacity);
133 return new _GrowableObjectArray<T>.withData(data); 135 return new _GrowableObjectArray<T>.withData(data);
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 } 345 }
344 346
345 Set<T> toSet() { 347 Set<T> toSet() {
346 return new Set<T>.from(this); 348 return new Set<T>.from(this);
347 } 349 }
348 350
349 Map<int, T> asMap() { 351 Map<int, T> asMap() {
350 return IterableMixinWorkaround.asMapList(this); 352 return IterableMixinWorkaround.asMapList(this);
351 } 353 }
352 } 354 }
OLDNEW
« no previous file with comments | « runtime/lib/array.dart ('k') | runtime/lib/typeddata.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698