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

Unified Diff: compiler/lib/implementation/array.dart

Issue 8271029: Implement List.insertRange. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: '' Created 9 years, 2 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 | compiler/lib/implementation/array.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: compiler/lib/implementation/array.dart
===================================================================
--- compiler/lib/implementation/array.dart (revision 424)
+++ compiler/lib/implementation/array.dart (working copy)
@@ -120,7 +120,8 @@
int get length() native;
void _setLength(int length) native;
void _add(T value) native;
- void _splice(int start, int length) native;
+ void _removeRange(int start, int length) native;
+ void _insertRange(int start, int length, T initialValue) native;
void forEach(void f(T element)) {
Collections.forEach(this, f);
@@ -158,9 +159,7 @@
if (length == 0) {
return;
}
- if (length < 0) {
- throw new IllegalArgumentException("negative length $length");
- }
+ Arrays.rangeCheck(this, start, length);
Arrays.copy(from, startFrom, this, start, length);
}
@@ -172,22 +171,27 @@
if (length == 0) {
return;
}
+ Arrays.rangeCheck(this, start, length);
+ _removeRange(start, length);
+ }
+
+ void insertRange(int start, int length, [T initialValue = null]) {
+ if (_isFixed) {
+ throw const UnsupportedOperationException(
+ "Cannot insert range in a non-extendable array");
+ }
+ if (length == 0) {
+ return;
+ }
if (length < 0) {
throw new IllegalArgumentException("negative length $length");
}
- if (start < 0 || start >= this.length) {
+ if (start < 0 || start > this.length) {
throw new IndexOutOfRangeException(start);
}
- if (start + length > this.length) {
- throw new IndexOutOfRangeException(start + length);
- }
- _splice(start, length);
+ _insertRange(start, length, initialValue);
}
- void insertRange(int start, int length, [T initialValue = null]) {
- throw const NotImplementedException();
- }
-
List<T> getRange(int start, int length) {
if (length == 0) return [];
Arrays.rangeCheck(this, start, length);
« no previous file with comments | « no previous file | compiler/lib/implementation/array.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698