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

Side by Side Diff: tests/language/optimized_constant_array_string_access_test.dart

Issue 18563006: More tests updated to optimize code (Part 2). (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 5 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
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 // VMOptions=--optimization-counter-threshold=10 --no-use-osr
4 5
5 import "package:expect/expect.dart"; 6 import "package:expect/expect.dart";
6 7
7 // Test optimized constant string and constant array access. 8 // Test optimized constant string and constant array access.
8 9
9 int testConstantStringAndIndexCodeUnitAt() { 10 int testConstantStringAndIndexCodeUnitAt() {
10 int test(b) { 11 int test(b) {
11 if (b) return "hest".codeUnitAt(400); 12 if (b) return "hest".codeUnitAt(400);
12 return "hest".codeUnitAt(2); 13 return "hest".codeUnitAt(2);
13 } 14 }
14 15
15 Expect.throws(() => test(true)); 16 Expect.throws(() => test(true));
16 for (int i = 0; i < 10000; i++) test(false); 17 for (int i = 0; i < 20; i++) test(false);
17 Expect.throws(() => test(true)); 18 Expect.throws(() => test(true));
18 } 19 }
19 20
20 21
21 int testConstantArrayAndIndexAt() { 22 int testConstantArrayAndIndexAt() {
22 int testPositive(b) { 23 int testPositive(b) {
23 var a = const [1,2,3,4]; 24 var a = const [1,2,3,4];
24 if (b) return a[400]; 25 if (b) return a[400];
25 return a[2]; 26 return a[2];
26 } 27 }
27 28
28 int testNegative(b) { 29 int testNegative(b) {
29 var a = const [1,2,3,4]; 30 var a = const [1,2,3,4];
30 if (b) return a[-1]; 31 if (b) return a[-1];
31 return a[2]; 32 return a[2];
32 } 33 }
33 34
34 Expect.throws(() => testPositive(true)); 35 Expect.throws(() => testPositive(true));
35 for (int i = 0; i < 10000; i++) testPositive(false); 36 for (int i = 0; i < 20; i++) testPositive(false);
36 Expect.throws(() => testPositive(true)); 37 Expect.throws(() => testPositive(true));
37 38
38 Expect.throws(() => testNegative(true)); 39 Expect.throws(() => testNegative(true));
39 for (int i = 0; i < 10000; i++) testNegative(false); 40 for (int i = 0; i < 20; i++) testNegative(false);
40 Expect.throws(() => testNegative(true)); 41 Expect.throws(() => testNegative(true));
41 } 42 }
42 43
43 44
44 foo(a) { 45 foo(a) {
45 if (a == 1) { return 2; } 46 if (a == 1) { return 2; }
46 var aa = const [1, 2]; 47 var aa = const [1, 2];
47 return aa[2.3]; 48 return aa[2.3];
48 } 49 }
49 50
50 51
51 int testNonSmiIndex() { 52 int testNonSmiIndex() {
52 for (int i = 0; i < 10000; i++) { foo(1); } 53 for (int i = 0; i < 20; i++) { foo(1); }
53 Expect.throws(() => foo(2)); 54 Expect.throws(() => foo(2));
54 } 55 }
55 56
56 57
57 main() { 58 main() {
58 testConstantStringAndIndexCodeUnitAt(); 59 testConstantStringAndIndexCodeUnitAt();
59 testConstantArrayAndIndexAt(); 60 testConstantArrayAndIndexAt();
60 testNonSmiIndex(); 61 testNonSmiIndex();
61 } 62 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698