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