OLD | NEW |
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 part of _interceptors; | 5 part of _interceptors; |
6 | 6 |
7 /** | 7 /** |
8 * The interceptor class for [List]. The compiler recognizes this | 8 * The interceptor class for [List]. The compiler recognizes this |
9 * class as an interceptor, and changes references to [:this:] to | 9 * class as an interceptor, and changes references to [:this:] to |
10 * actually use the receiver of the method, which is generated as an extra | 10 * actually use the receiver of the method, which is generated as an extra |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 if (index is !int) throw new ArgumentError(index); | 117 if (index is !int) throw new ArgumentError(index); |
118 if (index < 0 || index > length) { | 118 if (index < 0 || index > length) { |
119 throw new RangeError.value(index); | 119 throw new RangeError.value(index); |
120 } | 120 } |
121 JS('void', r'#.splice(#, 0, #)', this, index, value); | 121 JS('void', r'#.splice(#, 0, #)', this, index, value); |
122 } | 122 } |
123 | 123 |
124 void insertAll(int index, Iterable<E> iterable) { | 124 void insertAll(int index, Iterable<E> iterable) { |
125 checkGrowable('insertAll'); | 125 checkGrowable('insertAll'); |
126 RangeError.checkValueInInterval(index, 0, this.length, "index"); | 126 RangeError.checkValueInInterval(index, 0, this.length, "index"); |
127 if (iterable is! EfficientLengthIterable) { | 127 if (iterable is! EfficientLength) { |
128 iterable = iterable.toList(); | 128 iterable = iterable.toList(); |
129 } | 129 } |
130 int insertionLength = iterable.length; | 130 int insertionLength = iterable.length; |
131 this.length += insertionLength; | 131 this.length += insertionLength; |
132 int end = index + insertionLength; | 132 int end = index + insertionLength; |
133 this.setRange(end, this.length, this, index); | 133 this.setRange(end, this.length, this, index); |
134 this.setRange(index, end, iterable); | 134 this.setRange(index, end, iterable); |
135 } | 135 } |
136 | 136 |
137 void setAll(int index, Iterable<E> iterable) { | 137 void setAll(int index, Iterable<E> iterable) { |
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
432 RangeError.checkValidRange(start, end, this.length); | 432 RangeError.checkValidRange(start, end, this.length); |
433 for (int i = start; i < end; i++) { | 433 for (int i = start; i < end; i++) { |
434 // Store is safe since [fillValue] type has been checked as parameter. | 434 // Store is safe since [fillValue] type has been checked as parameter. |
435 JS('', '#[#] = #', this, i, fillValue); | 435 JS('', '#[#] = #', this, i, fillValue); |
436 } | 436 } |
437 } | 437 } |
438 | 438 |
439 void replaceRange(int start, int end, Iterable<E> replacement) { | 439 void replaceRange(int start, int end, Iterable<E> replacement) { |
440 checkGrowable('replace range'); | 440 checkGrowable('replace range'); |
441 RangeError.checkValidRange(start, end, this.length); | 441 RangeError.checkValidRange(start, end, this.length); |
442 if (replacement is! EfficientLengthIterable) { | 442 if (replacement is! EfficientLength) { |
443 replacement = replacement.toList(); | 443 replacement = replacement.toList(); |
444 } | 444 } |
445 int removeLength = end - start; | 445 int removeLength = end - start; |
446 int insertLength = replacement.length; | 446 int insertLength = replacement.length; |
447 if (removeLength >= insertLength) { | 447 if (removeLength >= insertLength) { |
448 int delta = removeLength - insertLength; | 448 int delta = removeLength - insertLength; |
449 int insertEnd = start + insertLength; | 449 int insertEnd = start + insertLength; |
450 int newLength = this.length - delta; | 450 int newLength = this.length - delta; |
451 this.setRange(start, insertEnd, replacement); | 451 this.setRange(start, insertEnd, replacement); |
452 if (delta != 0) { | 452 if (delta != 0) { |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
640 | 640 |
641 if (_index >= length) { | 641 if (_index >= length) { |
642 _current = null; | 642 _current = null; |
643 return false; | 643 return false; |
644 } | 644 } |
645 _current = _iterable[_index]; | 645 _current = _iterable[_index]; |
646 _index++; | 646 _index++; |
647 return true; | 647 return true; |
648 } | 648 } |
649 } | 649 } |
OLD | NEW |