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

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

Issue 12256037: Fix bug in optimizing string .length loads. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 10 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 | « runtime/vm/flow_graph_optimizer.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 4
5 // Test optimized charCodeAt and array access. 5 // Test optimized charCodeAt and array access.
6 6
7 String one_byte = "hest"; 7 String one_byte = "hest";
8 String two_byte = "høns"; 8 String two_byte = "høns";
9 9
10 int testOneByteCharCodeAt(String x, int i) { 10 int testOneByteCharCodeAt(String x, int j) {
11 int test() { 11 int test() {
12 return x.charCodeAt(i); 12 return x.charCodeAt(j);
13 } 13 }
14 for (int i = 0; i < 10000; i++) test(); 14 for (int i = 0; i < 10000; i++) test();
15 return test(); 15 return test();
16 } 16 }
17 17
18 18
19 int testTwoByteCharCodeAt(String x, int i) { 19 int testTwoByteCharCodeAt(String x, int j) {
20 int test() { 20 int test() {
21 return x.charCodeAt(i); 21 return x.charCodeAt(j);
22 } 22 }
23 for (int i = 0; i < 10000; i++) test(); 23 for (int i = 0; i < 10000; i++) test();
24 return test(); 24 return test();
25 } 25 }
26 26
27 27
28 int testConstantStringCharCodeAt(int i) { 28 int testConstantStringCharCodeAt(int j) {
29 int test() { 29 int test() {
30 return "høns".charCodeAt(i); 30 return "høns".charCodeAt(j);
31 } 31 }
32 for (int i = 0; i < 10000; i++) test(); 32 for (int i = 0; i < 10000; i++) test();
33 return test(); 33 return test();
34 } 34 }
35 35
36 36
37 int testConstantIndexCharCodeAt(String x) { 37 int testConstantIndexCharCodeAt(String x) {
38 int test() { 38 int test() {
39 return x.charCodeAt(1); 39 return x.charCodeAt(1);
40 } 40 }
41 for (int i = 0; i < 10000; i++) test(); 41 for (int i = 0; i < 10000; i++) test();
42 return test(); 42 return test();
43 } 43 }
44 44
45 45
46 int testOneByteCharCodeAtInLoop(var x) {
47 var result = 0;
48 for (int i = 0; i < x.length; i++) {
49 result += x.charCodeAt(i);
50 }
51 return result;
52 }
53
54
55 int testTwoByteCharCodeAtInLoop(var x) {
56 var result = 0;
57 for (int i = 0; i < x.length; i++) {
58 result += x.charCodeAt(i);
59 }
60 return result;
61 }
62
63
46 main() { 64 main() {
47 Expect.equals(101, testOneByteCharCodeAt(one_byte, 1)); 65 for (int j = 0; j < 10; j++) {
48 Expect.equals(248, testTwoByteCharCodeAt(two_byte, 1)); 66 Expect.equals(101, testOneByteCharCodeAt(one_byte, 1));
49 Expect.equals(248, testConstantStringCharCodeAt(1)); 67 Expect.equals(248, testTwoByteCharCodeAt(two_byte, 1));
50 Expect.equals(101, testConstantIndexCharCodeAt(one_byte)); 68 Expect.equals(248, testConstantStringCharCodeAt(1));
69 Expect.equals(101, testConstantIndexCharCodeAt(one_byte));
70 }
71 for (int j = 0; j < 2000; j++) {
72 Expect.equals(436, testOneByteCharCodeAtInLoop(one_byte));
73 Expect.equals(577, testTwoByteCharCodeAtInLoop(two_byte));
74 }
75 Expect.throws(() => testOneByteCharCodeAtInLoop(123));
76 Expect.throws(() => testTwoByteCharCodeAtInLoop(123));
51 } 77 }
78
OLDNEW
« no previous file with comments | « runtime/vm/flow_graph_optimizer.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698