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

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

Issue 509373003: Manually inline fixed-size list's forEach, to make it possible for the VM to optimize. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Clean up iterator and force inline. 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 | runtime/vm/method_recognizer.h » ('j') | runtime/vm/method_recognizer.h » ('J')
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 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 return result; 110 return result;
111 } 111 }
112 112
113 // Iterable interface. 113 // Iterable interface.
114 114
115 bool contains(Object element) { 115 bool contains(Object element) {
116 return IterableMixinWorkaround.contains(this, element); 116 return IterableMixinWorkaround.contains(this, element);
117 } 117 }
118 118
119 void forEach(f(E element)) { 119 void forEach(f(E element)) {
120 IterableMixinWorkaround.forEach(this, f); 120 final length = this.length;
121 for (int i = 0; i < length; i++) {
122 f(this[i]);
123 }
121 } 124 }
122 125
123 String join([String separator = ""]) { 126 String join([String separator = ""]) {
124 return IterableMixinWorkaround.joinList(this, separator); 127 return IterableMixinWorkaround.joinList(this, separator);
125 } 128 }
126 129
127 Iterable map(f(E element)) { 130 Iterable map(f(E element)) {
128 return IterableMixinWorkaround.mapList(this, f); 131 return IterableMixinWorkaround.mapList(this, f);
129 } 132 }
130 133
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
366 return new IterableMixinWorkaround<E>().getRangeList(this, start, end); 369 return new IterableMixinWorkaround<E>().getRangeList(this, start, end);
367 } 370 }
368 371
369 // Collection interface. 372 // Collection interface.
370 373
371 bool contains(Object element) { 374 bool contains(Object element) {
372 return IterableMixinWorkaround.contains(this, element); 375 return IterableMixinWorkaround.contains(this, element);
373 } 376 }
374 377
375 void forEach(f(E element)) { 378 void forEach(f(E element)) {
376 IterableMixinWorkaround.forEach(this, f); 379 final length = this.length;
380 for (int i = 0; i < length; i++) {
381 f(this[i]);
382 }
377 } 383 }
378 384
379 Iterable map(f(E element)) { 385 Iterable map(f(E element)) {
380 return IterableMixinWorkaround.mapList(this, f); 386 return IterableMixinWorkaround.mapList(this, f);
381 } 387 }
382 388
383 String join([String separator = ""]) { 389 String join([String separator = ""]) {
384 return IterableMixinWorkaround.joinList(this, separator); 390 return IterableMixinWorkaround.joinList(this, separator);
385 } 391 }
386 392
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
532 Map<int, E> asMap() { 538 Map<int, E> asMap() {
533 return new IterableMixinWorkaround<E>().asMapList(this); 539 return new IterableMixinWorkaround<E>().asMapList(this);
534 } 540 }
535 } 541 }
536 542
537 543
538 // Iterator for arrays with fixed size. 544 // Iterator for arrays with fixed size.
539 class _FixedSizeArrayIterator<E> implements Iterator<E> { 545 class _FixedSizeArrayIterator<E> implements Iterator<E> {
540 final List<E> _array; 546 final List<E> _array;
541 final int _length; // Cache array length for faster access. 547 final int _length; // Cache array length for faster access.
542 int _position; 548 int _index;
543 E _current; 549 E _current;
544 550
545 _FixedSizeArrayIterator(List array) 551 _FixedSizeArrayIterator(List array)
546 : _array = array, _length = array.length, _position = -1 { 552 : _array = array, _length = array.length, _index = 0 {
547 assert(array is _List || array is _ImmutableList); 553 assert(array is _List || array is _ImmutableList);
548 } 554 }
549 555
556 E get current => _current;
557
550 bool moveNext() { 558 bool moveNext() {
551 int nextPosition = _position + 1; 559 if (_index >= _length) {
552 if (nextPosition < _length) { 560 _current = null;
553 _current = _array[nextPosition]; 561 return false;
554 _position = nextPosition;
555 return true;
556 } 562 }
557 _position = _length; 563 _current = _array[_index];
558 _current = null; 564 _index++;
559 return false; 565 return true;
560 }
561
562 E get current {
563 return _current;
564 } 566 }
565 } 567 }
OLDNEW
« no previous file with comments | « no previous file | runtime/vm/method_recognizer.h » ('j') | runtime/vm/method_recognizer.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698