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

Side by Side Diff: tests/standalone/array_bounds_check_generalization_test.dart

Issue 619903002: Generalize bounds checks. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4 //
5 // VMOptions=--optimization_counter_threshold=10 --no-use-osr
6
7 import "package:expect/expect.dart";
8
9 test1(a, start, step, N) {
10 var e;
11 for (var i = 0; i < N; i++) {
Florian Schneider 2014/10/07 11:40:48 Can you add a test with a nested loop as well? e.g
Vyacheslav Egorov (Google) 2014/10/07 18:57:27 Done
12 e = a[start + i * step];
13 }
14 return e;
15 }
16
17 test2(a, b) {
18 var e;
19 for (var i = 0, j = 0, k = 0; i < a.length; i++, j++, k++) {
20 e = b[k] = a[j];
21 }
22 return e;
23 }
24
25 test3(a, b) {
26 var e;
27 for (var i = 0, j = 1, k = 0; i < a.length - 1; i++, j++, k++) {
28 e = b[k] = a[j - 1];
29 }
30 return e;
31 }
32
33 test4(a, b) {
34 var e;
35 if (a.length < 2) {
36 return;
37 }
38
39 for (var i = 0, j = 1, k = 0; i < a.length - 1; i++, j++, k++) {
40 e = b[k] = a[j - 1];
41 }
42 return e;
43 }
44
45 test5(a, b, k0) {
46 var e;
47 if (a.length < 2) {
48 return;
49 }
50
51 if (k0 > 1) {
52 return;
53 }
54
55 for (var i = 0, j = 1, k = 0; i < a.length - 1; i++, j++, k++) {
56 e = b[k - k0] = a[j - 1];
57 }
58 return e;
59 }
60
61 main() {
62 var a = const [0, 1, 2, 3, 4, 5, 6, 7];
63 var b = new List(a.length);
64 for (var i = 0; i < 10000; i++) {
65 Expect.equals(a.last, test1(a, 0, 1, a.length));
66 Expect.equals(a.last, test2(a, b));
67 Expect.equals(a[a.length - 2], test3(a, b));
68 Expect.equals(a[a.length - 2], test4(a, b));
69 Expect.equals(a[a.length - 2], test5(a, b, 0));
70 }
71
72 test1(a, 0, 2, a.length ~/ 2);
73 Expect.throws(() => test1(a, 1, 1, a.length));
74 Expect.throws(() => test2(a, new List(a.length - 1)));
75 }
OLDNEW
« runtime/vm/intermediate_language_ia32.cc ('K') | « runtime/vm/stack_frame.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698