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

Unified 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: Force inline immutable lists. Created 6 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | runtime/vm/method_recognizer.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/lib/array.dart
diff --git a/runtime/lib/array.dart b/runtime/lib/array.dart
index a24e404db02a382ea323e9119bec2f350d28cdcc..1d49d3b746dfbd89e26907d792db0239e35aa8ef 100644
--- a/runtime/lib/array.dart
+++ b/runtime/lib/array.dart
@@ -117,7 +117,10 @@ class _List<E> implements List<E> {
}
void forEach(f(E element)) {
- IterableMixinWorkaround.forEach(this, f);
+ final length = this.length;
+ for (int i = 0; i < length; i++) {
+ f(this[i]);
+ }
}
String join([String separator = ""]) {
@@ -373,7 +376,10 @@ class _ImmutableList<E> implements List<E> {
}
void forEach(f(E element)) {
- IterableMixinWorkaround.forEach(this, f);
+ final length = this.length;
+ for (int i = 0; i < length; i++) {
+ f(this[i]);
+ }
}
Iterable map(f(E element)) {
@@ -539,27 +545,23 @@ class _ImmutableList<E> implements List<E> {
class _FixedSizeArrayIterator<E> implements Iterator<E> {
final List<E> _array;
final int _length; // Cache array length for faster access.
- int _position;
+ int _index;
E _current;
_FixedSizeArrayIterator(List array)
- : _array = array, _length = array.length, _position = -1 {
+ : _array = array, _length = array.length, _index = 0 {
assert(array is _List || array is _ImmutableList);
}
+ E get current => _current;
+
bool moveNext() {
- int nextPosition = _position + 1;
- if (nextPosition < _length) {
- _current = _array[nextPosition];
- _position = nextPosition;
- return true;
+ if (_index >= _length) {
+ _current = null;
+ return false;
}
- _position = _length;
- _current = null;
- return false;
- }
-
- E get current {
- return _current;
+ _current = _array[_index];
+ _index++;
+ return true;
}
}
« no previous file with comments | « no previous file | runtime/vm/method_recognizer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698