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

Side by Side Diff: compiler/lib/implementation/arrays.dart

Issue 9702034: Removes dartc reliance on its own libraries, now can be targeted at any implementation's libraries (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: junit tests fixed Created 8 years, 9 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « compiler/lib/implementation/array.js ('k') | compiler/lib/implementation/bool.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
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.
4
5 // TODO(ngeoffray): Rename to Lists.
6 class Arrays {
7
8 static void copy(List<Object> src, int srcStart,
9 List<Object> dst, int dstStart, int count) {
10 if (srcStart === null) srcStart = 0;
11 if (dstStart === null) dstStart = 0;
12
13 if (srcStart < dstStart) {
14 for (int i = srcStart + count - 1, j = dstStart + count - 1;
15 i >= srcStart; i--, j--) {
16 dst[j] = src[i];
17 }
18 } else {
19 for (int i = srcStart, j = dstStart; i < srcStart + count; i++, j++) {
20 dst[j] = src[i];
21 }
22 }
23 }
24
25 /**
26 * Returns the index in the array [a] of the given [element], starting
27 * the search at index [startIndex] to [endIndex] (exclusive).
28 * Returns -1 if [element] is not found.
29 */
30 static int indexOf(List a,
31 Object element,
32 int startIndex,
33 int endIndex) {
34 if (startIndex >= a.length) {
35 return -1;
36 }
37 if (startIndex < 0) {
38 startIndex = 0;
39 }
40 for (int i = startIndex; i < endIndex; i++) {
41 if (a[i] == element) {
42 return i;
43 }
44 }
45 return -1;
46 }
47
48 /**
49 * Returns the last index in the array [a] of the given [element], starting
50 * the search at index [startIndex] to 0.
51 * Returns -1 if [element] is not found.
52 */
53 static int lastIndexOf(List a, Object element, int startIndex) {
54 if (startIndex < 0) {
55 return -1;
56 }
57 if (startIndex >= a.length) {
58 startIndex = a.length - 1;
59 }
60 for (int i = startIndex; i >= 0; i--) {
61 if (a[i] == element) {
62 return i;
63 }
64 }
65 return -1;
66 }
67
68 static void rangeCheck(List a, int start, int length) {
69 if (length < 0) {
70 throw new IllegalArgumentException("negative length $length");
71 }
72 if (start < 0 || start >= a.length) {
73 throw new IndexOutOfRangeException(start);
74 }
75 if (start + length > a.length) {
76 throw new IndexOutOfRangeException(start + length);
77 }
78 }
79 }
OLDNEW
« no previous file with comments | « compiler/lib/implementation/array.js ('k') | compiler/lib/implementation/bool.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698