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

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

Issue 518273004: Don't always call _copyFromObjectArray. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 3 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 | 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 5
6 // TODO(srdjan): Use shared array implementation. 6 // TODO(srdjan): Use shared array implementation.
7 class _List<E> implements List<E> { 7 class _List<E> implements List<E> {
8 8
9 factory _List(length) native "List_allocate"; 9 factory _List(length) native "List_allocate";
10 10
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 // List interface. 59 // List interface.
60 void setRange(int start, int end, Iterable<E> iterable, [int skipCount = 0]) { 60 void setRange(int start, int end, Iterable<E> iterable, [int skipCount = 0]) {
61 if (start < 0 || start > this.length) { 61 if (start < 0 || start > this.length) {
62 throw new RangeError.range(start, 0, this.length); 62 throw new RangeError.range(start, 0, this.length);
63 } 63 }
64 if (end < start || end > this.length) { 64 if (end < start || end > this.length) {
65 throw new RangeError.range(end, start, this.length); 65 throw new RangeError.range(end, start, this.length);
66 } 66 }
67 int length = end - start; 67 int length = end - start;
68 if (length == 0) return; 68 if (length == 0) return;
69 69 if (identical(this, iterable)) {
70 if (ClassID.getID(iterable) == ClassID.cidOneByteString) { 70 Lists.copy(iterable, skipcount, this, start, length);
71 } else if (ClassID.getID(iterable) == ClassID.cidArray && length > 128) {
srdjan 2014/09/02 18:33:58 Please add parentheses.
71 _copyFromObjectArray(iterable, skipCount, start, length); 72 _copyFromObjectArray(iterable, skipCount, start, length);
Lasse Reichstein Nielsen 2014/09/02 14:29:09 Good thing this wasn't called before due to the in
73 } else if (iterable is List) {
74 Lists.copy(iterable, skipCount, this, start, length);
72 } else { 75 } else {
73 if (iterable is List) { 76 Iterator it = iterable.iterator;
74 Lists.copy(iterable, skipCount, this, start, length); 77 while (skipCount > 0) {
75 } else { 78 if (!it.moveNext()) return;
76 Iterator it = iterable.iterator; 79 skipCount--;
77 while (skipCount > 0) { 80 }
78 if (!it.moveNext()) return; 81 for (int i = start; i < end; i++) {
79 skipCount--; 82 if (!it.moveNext()) return;
80 } 83 this[i] = it.current;
81 for (int i = start; i < end; i++) {
82 if (!it.moveNext()) return;
83 this[i] = it.current;
84 }
85 } 84 }
86 } 85 }
87 } 86 }
88 87
89 void removeRange(int start, int end) { 88 void removeRange(int start, int end) {
90 throw NonGrowableListError.remove(); 89 throw NonGrowableListError.remove();
91 } 90 }
92 91
93 void replaceRange(int start, int end, Iterable<E> iterable) { 92 void replaceRange(int start, int end, Iterable<E> iterable) {
94 throw NonGrowableListError.remove(); 93 throw NonGrowableListError.remove();
95 } 94 }
96 95
97 void fillRange(int start, int end, [E fillValue]) { 96 void fillRange(int start, int end, [E fillValue]) {
98 IterableMixinWorkaround.fillRangeList(this, start, end, fillValue); 97 IterableMixinWorkaround.fillRangeList(this, start, end, fillValue);
99 } 98 }
100 99
101 List<E> sublist(int start, [int end]) { 100 List<E> sublist(int start, [int end]) {
102 Lists.indicesCheck(this, start, end); 101 Lists.indicesCheck(this, start, end);
103 if (end == null) end = this.length; 102 if (end == null) end = this.length;
104 int length = end - start; 103 int length = end - start;
105 if (start == end) return <E>[]; 104 if (start == end) return <E>[];
106 List list = new _List(length); 105 List list = new _List(length);
107 list._copyFromObjectArray(this, start, 0, length); 106 if (length < 128) {
Vyacheslav Egorov (Google) 2014/09/02 14:31:15 I don't like that this is repeated. Can we have
107 for (int i = 0; i < length; i++) {
108 list[i] = this[start + i];
109 }
110 } else {
111 list._copyFromObjectArray(this, start, 0, length);
112 }
108 var result = new _GrowableList<E>.withData(list); 113 var result = new _GrowableList<E>.withData(list);
109 result._setLength(length); 114 result._setLength(length);
110 return result; 115 return result;
111 } 116 }
112 117
113 // Iterable interface. 118 // Iterable interface.
114 119
115 bool contains(Object element) { 120 bool contains(Object element) {
116 return IterableMixinWorkaround.contains(this, element); 121 return IterableMixinWorkaround.contains(this, element);
117 } 122 }
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 E get single { 255 E get single {
251 if (length == 1) return this[0]; 256 if (length == 1) return this[0];
252 if (length == 0) throw IterableElementError.noElement(); 257 if (length == 0) throw IterableElementError.noElement();
253 throw IterableElementError.tooMany(); 258 throw IterableElementError.tooMany();
254 } 259 }
255 260
256 List<E> toList({ bool growable: true }) { 261 List<E> toList({ bool growable: true }) {
257 var length = this.length; 262 var length = this.length;
258 if (length > 0) { 263 if (length > 0) {
259 var result = growable ? new _List(length) : new _List<E>(length); 264 var result = growable ? new _List(length) : new _List<E>(length);
260 result._copyFromObjectArray(this, 0, 0, length); 265 if (length < 128) {
266 for (int i = 0; i < length; i++) {
267 result[i] = this[i];
268 }
269 } else {
270 result._copyFromObjectArray(this, 0, 0, length);
271 }
261 if (growable) { 272 if (growable) {
262 result = new _GrowableList<E>.withData(result); 273 result = new _GrowableList<E>.withData(result);
263 result._setLength(length); 274 result._setLength(length);
264 } 275 }
265 return result; 276 return result;
266 } 277 }
267 // _GrowableList.withData must not be called with empty list. 278 // _GrowableList.withData must not be called with empty list.
268 return growable ? <E>[] : new List<E>(0); 279 return growable ? <E>[] : new List<E>(0);
269 } 280 }
270 281
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after
558 bool moveNext() { 569 bool moveNext() {
559 if (_index >= _length) { 570 if (_index >= _length) {
560 _current = null; 571 _current = null;
561 return false; 572 return false;
562 } 573 }
563 _current = _array[_index]; 574 _current = _array[_index];
564 _index++; 575 _index++;
565 return true; 576 return true;
566 } 577 }
567 } 578 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698