OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 import "package:expect/expect.dart"; |
| 6 |
5 // Test that constant propagation correctly updates phis when predecessor's | 7 // Test that constant propagation correctly updates phis when predecessor's |
6 // reachability changes. | 8 // reachability changes. |
7 | 9 |
8 final keys = const ["keyA"]; | 10 final keys = const ["keyA"]; |
9 final values = const ["a"]; | 11 final values = const ["a"]; |
10 | 12 |
11 main() { | 13 main() { |
12 for (var i = 0; i < 10000; i++) test(keys[0]); | 14 for (var i = 0; i < 10000; i++) test(keys[0]); |
13 } | 15 } |
14 | 16 |
15 test(key) { | 17 test(key) { |
16 var ref = key2value(key); | 18 var ref = key2value(key); |
17 Expect.equals("a", (ref == null) ? "-" : ref); | 19 Expect.equals("a", (ref == null) ? "-" : ref); |
18 } | 20 } |
19 | 21 |
20 key2value(key) { | 22 key2value(key) { |
21 var index = indexOf(keys, key); | 23 var index = indexOf(keys, key); |
22 return (index == -1) ? null : values[index]; | 24 return (index == -1) ? null : values[index]; |
23 } | 25 } |
24 | 26 |
25 indexOf(keys, key) { | 27 indexOf(keys, key) { |
26 for (var i = keys.length - 1; i >= 0; i--) { | 28 for (var i = keys.length - 1; i >= 0; i--) { |
27 var equals = keys[i] == key; | 29 var equals = keys[i] == key; |
28 if (equals) return i; | 30 if (equals) return i; |
29 } | 31 } |
30 return -1; | 32 return -1; |
31 } | 33 } |
OLD | NEW |