| OLD | NEW |
| (Empty) |
| 1 // Expectation for test: | |
| 2 // // Method to test: function(test) | |
| 3 // import 'package:expect/expect.dart'; | |
| 4 // | |
| 5 // // This example illustrates a case we wish to do better in terms of inlining
and | |
| 6 // // code generation. | |
| 7 // // | |
| 8 // // Naively this function would be compiled without inlining Wrapper.[], | |
| 9 // // JSArray.[] and Wrapper.[]= because: | |
| 10 // // JSArray.[] is too big (14 nodes) | |
| 11 // // Wrapper.[] is too big if we force inlining of JSArray (15 nodes) | |
| 12 // // Wrapper.[]= is even bigger (46 nodes) | |
| 13 // // | |
| 14 // // We now do specialization of [] and []= by adding guards and injecting buil
tin | |
| 15 // // operators. This made it possible to inline []. We still don't see []= inli
ned | |
| 16 // // yet, that might require that we improve the inlining counting heuristics a | |
| 17 // // bit. | |
| 18 // @NoInline() | |
| 19 // test(data, x) { | |
| 20 // data[x + 1] = data[x]; | |
| 21 // } | |
| 22 // | |
| 23 // main() { | |
| 24 // var wrapper = new Wrapper(); | |
| 25 // wrapper[33] = wrapper[1]; // make Wrapper.[]= and [] used more than once. | |
| 26 // print(test(new Wrapper(), int.parse('2'))); | |
| 27 // } | |
| 28 // | |
| 29 // class Wrapper { | |
| 30 // final List arr = <bool>[true, false, false, true]; | |
| 31 // operator[](int i) => this.arr[i]; | |
| 32 // operator[]=(int i, v) { | |
| 33 // if (i > arr.length - 1) arr.length = i + 1; | |
| 34 // return arr[i] = v; | |
| 35 // } | |
| 36 // } | |
| 37 | |
| 38 function(data, x) { | |
| 39 var v0 = J.$add$ns(x, 1), v1 = data.arr; | |
| 40 if (x >>> 0 !== x || x >= v1.length) | |
| 41 return H.ioore(v1, x); | |
| 42 data.$indexSet(0, v0, v1[x]); | |
| 43 } | |
| OLD | NEW |