| OLD | NEW |
| (Empty) | |
| 1 foo(x, list) { |
| 2 var sum = 0; |
| 3 for (int k = 0; k < 10; k++) { |
| 4 // Everything can be hoisted out up to the index access which is |
| 5 // blocked by the bounds check. |
| 6 var a = x.left.left; |
| 7 var b = x.left.right; |
| 8 var c = x.right.left; |
| 9 var d = x.right.right; |
| 10 var i = a.value + c.value; |
| 11 var j = b.value + d.value; |
| 12 var z = list[i * j] + i; |
| 13 sum += z; |
| 14 } |
| 15 return sum; |
| 16 } |
| 17 // Use a different class for each level in the tree, so type inference |
| 18 // is not confused. |
| 19 class Root { |
| 20 Branch left, right; |
| 21 Root(this.left, this.right); |
| 22 } |
| 23 class Branch { |
| 24 Leaf left, right; |
| 25 Branch(this.left, this.right); |
| 26 } |
| 27 class Leaf { |
| 28 int value; |
| 29 Leaf(this.value); |
| 30 } |
| 31 main() { |
| 32 var x1 = new Leaf(1); |
| 33 var x2 = new Leaf(10); |
| 34 var x3 = new Leaf(20); |
| 35 var x4 = new Leaf(-10); |
| 36 var y1 = new Branch(x1, x2); |
| 37 var y2 = new Branch(x3, x4); |
| 38 var z = new Root(y1, y2); |
| 39 print(foo(z, [1,2,3,4,5,6,7,8,9,10])); |
| 40 } |
| 41 |
| OLD | NEW |