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

Unified Diff: sdk/lib/_internal/compiler/implementation/lib/js_array.dart

Issue 12386072: Move Arrays class to private library. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments. Created 7 years, 10 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: sdk/lib/_internal/compiler/implementation/lib/js_array.dart
diff --git a/sdk/lib/_internal/compiler/implementation/lib/js_array.dart b/sdk/lib/_internal/compiler/implementation/lib/js_array.dart
index 70e47d640aa25f6cb9a412a9c71f738610f5ebba..9b73f4080cbd0388225a53463aec53ec2e9cfde1 100644
--- a/sdk/lib/_internal/compiler/implementation/lib/js_array.dart
+++ b/sdk/lib/_internal/compiler/implementation/lib/js_array.dart
@@ -156,7 +156,30 @@ class JSArray<E> implements List<E> {
void insertRange(int start, int length, [E initialValue]) {
checkGrowable(this, 'insertRange');
- return listInsertRange(this, start, length, initialValue);
+ if (length == 0) {
+ return;
+ }
+ if (length is !int) throw new ArgumentError(length);
+ if (length < 0) throw new ArgumentError(length);
+ if (start is !int) throw new ArgumentError(start);
+
+ var receiver = this;
+ var receiverLength = receiver.length;
+ if (start < 0 || start > receiverLength) {
+ throw new RangeError.value(start);
+ }
+ receiver.length = receiverLength + length;
+ Arrays.copy(receiver,
+ start,
+ receiver,
+ start + length,
+ receiverLength - start);
+ if (initialValue != null) {
+ for (int i = start; i < start + length; i++) {
+ receiver[i] = initialValue;
+ }
+ }
+ receiver.length = receiverLength + length;
}
E get first {
@@ -206,21 +229,7 @@ class JSArray<E> implements List<E> {
void setRange(int start, int length, List<E> from, [int startFrom = 0]) {
checkMutable(this, 'set range');
- if (length == 0) return;
- checkNull(start); // TODO(ahe): This is not specified but co19 tests it.
- checkNull(length); // TODO(ahe): This is not specified but co19 tests it.
- checkNull(from); // TODO(ahe): This is not specified but co19 tests it.
- checkNull(startFrom); // TODO(ahe): This is not specified but co19 tests it.
- if (start is !int) throw new ArgumentError(start);
- if (length is !int) throw new ArgumentError(length);
- if (startFrom is !int) throw new ArgumentError(startFrom);
- if (length < 0) throw new ArgumentError(length);
- if (start < 0) throw new RangeError.value(start);
- if (start + length > this.length) {
- throw new RangeError.value(start + length);
- }
-
- Arrays.copy(from, startFrom, this, start, length);
+ IterableMixinWorkaround.setRangeList(this, start, length, from, startFrom);
}
bool any(bool f(E element)) => IterableMixinWorkaround.any(this, f);
@@ -235,13 +244,11 @@ class JSArray<E> implements List<E> {
}
int indexOf(E element, [int start = 0]) {
- if (start is !int) throw new ArgumentError(start);
- return Arrays.indexOf(this, element, start, length);
+ return IterableMixinWorkaround.indexOfList(this, element, start);
}
int lastIndexOf(E element, [int start]) {
- if (start == null) start = this.length - 1;
- return Arrays.lastIndexOf(this, element, start);
+ return IterableMixinWorkaround.lastIndexOfList(this, element, start);
}
bool contains(E other) {

Powered by Google App Engine
This is Rietveld 408576698