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

Unified Diff: runtime/lib/array.dart

Issue 536043002: Merge array allocation and List._copyFromObjectArray to provide fast path for large arrays. (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 side-by-side diff with in-line comments
Download patch
Index: runtime/lib/array.dart
diff --git a/runtime/lib/array.dart b/runtime/lib/array.dart
index b6d1a2e31275d713538fb46c74ae8017178f5ed3..68b51345c4dafe31b87f67a9a17cf8d76e471d5d 100644
--- a/runtime/lib/array.dart
+++ b/runtime/lib/array.dart
@@ -18,24 +18,21 @@ class _List<E> implements List<E> {
int get length native "List_getLength";
- void _copyFromObjectArray(_List src,
- int srcStart,
- int dstStart,
- int count) {
- if (count < 128) {
- for (int i = 0; i < count; i++) {
- this[dstStart + i] = src[srcStart + i];
+ List _slice(int start, int count, bool needTypeArgument) {
srdjan 2014/09/03 18:08:11 optional: needsTypeArgument.
Vyacheslav Egorov (Google) 2014/09/03 20:35:18 Done.
+ if (count <= 64) {
+ final result = needTypeArgument ? new _List<E>(count)
+ : new _List(count);
srdjan 2014/09/03 18:08:11 What is the performance degradation if we always a
Vyacheslav Egorov (Google) 2014/09/03 20:35:18 I have not measured performance impact. I doubt th
+ for (int i = 0; i < result.length; i++) {
+ result[i] = this[start + i];
}
+ return result;
} else {
- _copyFromObjectArrayInternal(src, srcStart, dstStart, count);
+ return _sliceInternal(start, count, needTypeArgument);
}
}
- void _copyFromObjectArrayInternal(_List src,
- int srcStart,
- int dstStart,
- int count)
- native "List_copyFromObjectArray";
+ List _sliceInternal(int start, int count, bool needTypeArgument)
+ native "List_slice";
void insert(int index, E element) {
throw NonGrowableListError.add();
@@ -82,7 +79,7 @@ class _List<E> implements List<E> {
if (identical(this, iterable)) {
Lists.copy(iterable, skipCount, this, start, length);
} else if (ClassID.getID(iterable) == ClassID.cidArray) {
- _copyFromObjectArray(iterable, skipCount, start, length);
+ Lists.copy(iterable, skipCount, this, start, length);
} else if (iterable is List) {
Lists.copy(iterable, skipCount, this, start, length);
} else {
@@ -115,9 +112,7 @@ class _List<E> implements List<E> {
if (end == null) end = this.length;
int length = end - start;
if (start == end) return <E>[];
- List list = new _List(length);
- list._copyFromObjectArray(this, start, 0, length);
- var result = new _GrowableList<E>.withData(list);
+ var result = new _GrowableList<E>.withData(_slice(start, length, false));
result._setLength(length);
return result;
}
@@ -268,8 +263,7 @@ class _List<E> implements List<E> {
List<E> toList({ bool growable: true }) {
var length = this.length;
if (length > 0) {
- var result = growable ? new _List(length) : new _List<E>(length);
- result._copyFromObjectArray(this, 0, 0, length);
+ var result = _slice(0, length, !growable);
if (growable) {
result = new _GrowableList<E>.withData(result);
result._setLength(length);

Powered by Google App Engine
This is Rietveld 408576698