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

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

Issue 12282038: Remove deprecated string features. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Merge to head Created 7 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
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 CodeUnitAt 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 j) { 10 int testOneByteCodeUnitAt(String x, int j) {
11 int test() { 11 int test() {
12 return x.charCodeAt(j); 12 return x.codeUnitAt(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 j) { 19 int testTwoByteCodeUnitAt(String x, int j) {
20 int test() { 20 int test() {
21 return x.charCodeAt(j); 21 return x.codeUnitAt(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 j) { 28 int testConstantStringCodeUnitAt(int j) {
29 int test() { 29 int test() {
30 return "høns".charCodeAt(j); 30 return "høns".codeUnitAt(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 testConstantIndexCodeUnitAt(String x) {
38 int test() { 38 int test() {
39 return x.charCodeAt(1); 39 return x.codeUnitAt(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) { 46 int testOneByteCodeUnitAtInLoop(var x) {
47 var result = 0; 47 var result = 0;
48 for (int i = 0; i < x.length; i++) { 48 for (int i = 0; i < x.length; i++) {
49 result += x.charCodeAt(i); 49 result += x.codeUnitAt(i);
50 } 50 }
51 return result; 51 return result;
52 } 52 }
53 53
54 54
55 int testTwoByteCharCodeAtInLoop(var x) { 55 int testTwoByteCodeUnitAtInLoop(var x) {
56 var result = 0; 56 var result = 0;
57 for (int i = 0; i < x.length; i++) { 57 for (int i = 0; i < x.length; i++) {
58 result += x.charCodeAt(i); 58 result += x.codeUnitAt(i);
59 } 59 }
60 return result; 60 return result;
61 } 61 }
62 62
63 63
64 main() { 64 main() {
65 for (int j = 0; j < 10; j++) { 65 for (int j = 0; j < 10; j++) {
66 Expect.equals(101, testOneByteCharCodeAt(one_byte, 1)); 66 Expect.equals(101, testOneByteCodeUnitAt(one_byte, 1));
67 Expect.equals(248, testTwoByteCharCodeAt(two_byte, 1)); 67 Expect.equals(248, testTwoByteCodeUnitAt(two_byte, 1));
68 Expect.equals(248, testConstantStringCharCodeAt(1)); 68 Expect.equals(248, testConstantStringCodeUnitAt(1));
69 Expect.equals(101, testConstantIndexCharCodeAt(one_byte)); 69 Expect.equals(101, testConstantIndexCodeUnitAt(one_byte));
70 } 70 }
71 for (int j = 0; j < 2000; j++) { 71 for (int j = 0; j < 2000; j++) {
72 Expect.equals(436, testOneByteCharCodeAtInLoop(one_byte)); 72 Expect.equals(436, testOneByteCodeUnitAtInLoop(one_byte));
73 Expect.equals(577, testTwoByteCharCodeAtInLoop(two_byte)); 73 Expect.equals(577, testTwoByteCodeUnitAtInLoop(two_byte));
74 } 74 }
75 Expect.throws(() => testOneByteCharCodeAtInLoop(123)); 75 Expect.throws(() => testOneByteCodeUnitAtInLoop(123));
76 Expect.throws(() => testTwoByteCharCodeAtInLoop(123)); 76 Expect.throws(() => testTwoByteCodeUnitAtInLoop(123));
77 } 77 }
OLDNEW
« no previous file with comments | « tests/language/optimized_constant_array_string_access_test.dart ('k') | tests/language/static_inline_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698