| 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 // VMOptions=--optimization-counter-threshold=10 --no-use-osr |
| 5 |
| 6 // Test optimized CodeUnitAt and array access. |
| 7 |
| 8 import "package:expect/expect.dart"; |
| 9 |
| 10 |
| 11 String one_byte = "hest"; |
| 12 String two_byte = "h\u{2029}ns"; |
| 13 |
| 14 int testOneByteCodeUnitAt(String x, int j) { |
| 15 int test() { |
| 16 return x.codeUnitAt(j); |
| 17 } |
| 18 for (int i = 0; i < 20; i++) test(); |
| 19 return test(); |
| 20 } |
| 21 |
| 22 |
| 23 int testTwoByteCodeUnitAt(String x, int j) { |
| 24 int test() { |
| 25 return x.codeUnitAt(j); |
| 26 } |
| 27 for (int i = 0; i < 20; i++) test(); |
| 28 return test(); |
| 29 } |
| 30 |
| 31 |
| 32 int testConstantStringCodeUnitAt(int j) { |
| 33 int test() { |
| 34 return "høns".codeUnitAt(j); |
| 35 } |
| 36 for (int i = 0; i < 20; i++) test(); |
| 37 return test(); |
| 38 } |
| 39 |
| 40 |
| 41 int testConstantIndexCodeUnitAt(String x) { |
| 42 int test() { |
| 43 return x.codeUnitAt(1); |
| 44 } |
| 45 for (int i = 0; i < 20; i++) test(); |
| 46 return test(); |
| 47 } |
| 48 |
| 49 |
| 50 int testOneByteCodeUnitAtInLoop(var x) { |
| 51 var result = 0; |
| 52 for (int i = 0; i < x.length; i++) { |
| 53 result += x.codeUnitAt(i); |
| 54 } |
| 55 return result; |
| 56 } |
| 57 |
| 58 |
| 59 int testTwoByteCodeUnitAtInLoop(var x) { |
| 60 var result = 0; |
| 61 for (int i = 0; i < x.length; i++) { |
| 62 result += x.codeUnitAt(i); |
| 63 } |
| 64 return result; |
| 65 } |
| 66 |
| 67 |
| 68 main() { |
| 69 for (int j = 0; j < 10; j++) { |
| 70 Expect.equals(101, testOneByteCodeUnitAt(one_byte, 1)); |
| 71 Expect.equals(8233, testTwoByteCodeUnitAt(two_byte, 1)); |
| 72 Expect.equals(248, testConstantStringCodeUnitAt(1)); |
| 73 Expect.equals(101, testConstantIndexCodeUnitAt(one_byte)); |
| 74 } |
| 75 for (int j = 0; j < 20; j++) { |
| 76 Expect.equals(436, testOneByteCodeUnitAtInLoop(one_byte)); |
| 77 Expect.equals(8562, testTwoByteCodeUnitAtInLoop(two_byte)); |
| 78 } |
| 79 Expect.throws(() => testOneByteCodeUnitAtInLoop(123)); |
| 80 Expect.throws(() => testTwoByteCodeUnitAtInLoop(123)); |
| 81 } |
| OLD | NEW |