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