| OLD | NEW |
| (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 // Test optimized charCodeAt and array access. | |
| 6 | |
| 7 String one_byte = "hest"; | |
| 8 String two_byte = "høns"; | |
| 9 | |
| 10 int testOneByteCharCodeAt(String x, int i) { | |
| 11 int test() { | |
| 12 return x.charCodeAt(i); | |
| 13 } | |
| 14 for (int i = 0; i < 10000; i++) test(); | |
| 15 return test(); | |
| 16 } | |
| 17 | |
| 18 | |
| 19 int testTwoByteCharCodeAt(String x, int i) { | |
| 20 int test() { | |
| 21 return x.charCodeAt(i); | |
| 22 } | |
| 23 for (int i = 0; i < 10000; i++) test(); | |
| 24 return test(); | |
| 25 } | |
| 26 | |
| 27 | |
| 28 int testConstantStringCharCodeAt(int i) { | |
| 29 int test() { | |
| 30 return "høns".charCodeAt(i); | |
| 31 } | |
| 32 for (int i = 0; i < 10000; i++) test(); | |
| 33 return test(); | |
| 34 } | |
| 35 | |
| 36 | |
| 37 int testConstantIndexCharCodeAt(String x) { | |
| 38 int test() { | |
| 39 return x.charCodeAt(1); | |
| 40 } | |
| 41 for (int i = 0; i < 10000; i++) test(); | |
| 42 return test(); | |
| 43 } | |
| 44 | |
| 45 | |
| 46 main() { | |
| 47 Expect.equals(101, testOneByteCharCodeAt(one_byte, 1)); | |
| 48 Expect.equals(248, testTwoByteCharCodeAt(two_byte, 1)); | |
| 49 Expect.equals(248, testConstantStringCharCodeAt(1)); | |
| 50 Expect.equals(101, testConstantIndexCharCodeAt(one_byte)); | |
| 51 } | |
| OLD | NEW |