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

Side by Side Diff: tests/language/optimized_string_charat_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 [] on strings. 8 // Test optimized [] on strings.
8 9
9 var a = "abc"; 10 var a = "abc";
10 var b = "øbc"; 11 var b = "øbc";
11 var c = new String.fromCharCodes([123, 456, 789]); 12 var c = new String.fromCharCodes([123, 456, 789]);
12 13
13 test_charat(s, i) { 14 test_charat(s, i) {
14 return s[i]; 15 return s[i];
15 } 16 }
16 17
17 test_const_str(i) { 18 test_const_str(i) {
18 return "abc"[i]; 19 return "abc"[i];
19 } 20 }
20 21
21 22
22 test_const_index(s) { 23 test_const_index(s) {
23 return s[0]; 24 return s[0];
24 } 25 }
25 26
26 test_const_index2(s) { 27 test_const_index2(s) {
27 return s[3]; 28 return s[3];
28 } 29 }
29 30
30 main() { 31 main() {
31 Expect.equals("a", test_charat(a, 0)); 32 Expect.equals("a", test_charat(a, 0));
32 for (var i=0; i<10000; i++) test_charat(a, 0); 33 for (var i = 0; i < 20; i++) test_charat(a, 0);
33 Expect.equals("a", test_charat(a, 0)); 34 Expect.equals("a", test_charat(a, 0));
34 Expect.equals("b", test_charat(a, 1)); 35 Expect.equals("b", test_charat(a, 1));
35 Expect.equals("c", test_charat(a, 2)); 36 Expect.equals("c", test_charat(a, 2));
36 Expect.throws(() => test_charat(a, 3)); 37 Expect.throws(() => test_charat(a, 3));
37 38
38 Expect.equals("a", test_const_str(0)); 39 Expect.equals("a", test_const_str(0));
39 for (var i=0; i<10000; i++) test_const_str(0); 40 for (var i = 0; i < 20; i++) test_const_str(0);
40 Expect.equals("a", test_const_str(0)); 41 Expect.equals("a", test_const_str(0));
41 Expect.equals("b", test_const_str(1)); 42 Expect.equals("b", test_const_str(1));
42 Expect.equals("c", test_const_str(2)); 43 Expect.equals("c", test_const_str(2));
43 Expect.throws(() => test_const_str(3)); 44 Expect.throws(() => test_const_str(3));
44 45
45 Expect.equals("a", test_const_index(a)); 46 Expect.equals("a", test_const_index(a));
46 for (var i=0; i<10000; i++) test_const_index(a); 47 for (var i = 0; i < 20; i++) test_const_index(a);
47 Expect.equals("a", test_const_index(a)); 48 Expect.equals("a", test_const_index(a));
48 Expect.equals("ø", test_const_index(b)); 49 Expect.equals("ø", test_const_index(b));
49 Expect.equals(new String.fromCharCodes([123]), test_const_index(c)); 50 Expect.equals(new String.fromCharCodes([123]), test_const_index(c));
50 Expect.throws(() => test_const_index2(a)); 51 Expect.throws(() => test_const_index2(a));
51 52
52 Expect.equals("ø", test_charat(b, 0)); 53 Expect.equals("ø", test_charat(b, 0));
53 for (var i=0; i<10000; i++) test_charat(b, 0); 54 for (var i = 0; i < 20; i++) test_charat(b, 0);
54 Expect.equals("ø", test_charat(b, 0)); 55 Expect.equals("ø", test_charat(b, 0));
55 Expect.equals("b", test_charat(b, 1)); 56 Expect.equals("b", test_charat(b, 1));
56 Expect.equals("c", test_charat(b, 2)); 57 Expect.equals("c", test_charat(b, 2));
57 Expect.throws(() => test_charat(b, 3)); 58 Expect.throws(() => test_charat(b, 3));
58 59
59 Expect.equals(new String.fromCharCodes([123]), test_charat(c, 0)); 60 Expect.equals(new String.fromCharCodes([123]), test_charat(c, 0));
60 for (var i=0; i<10000; i++) test_charat(c, 0); 61 for (var i = 0; i < 20; i++) test_charat(c, 0);
61 Expect.equals(new String.fromCharCodes([123]), test_charat(c, 0)); 62 Expect.equals(new String.fromCharCodes([123]), test_charat(c, 0));
62 Expect.equals(new String.fromCharCodes([456]), test_charat(c, 1)); 63 Expect.equals(new String.fromCharCodes([456]), test_charat(c, 1));
63 Expect.equals(new String.fromCharCodes([789]), test_charat(c, 2)); 64 Expect.equals(new String.fromCharCodes([789]), test_charat(c, 2));
64 Expect.throws(() => test_charat(c, 3)); 65 Expect.throws(() => test_charat(c, 3));
65 66
66 67
67 } 68 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698