| OLD | NEW |
| 1 // Method to test: function(test) | 1 // Method to test: function(test) |
| 2 import 'package:expect/expect.dart'; | 2 import 'package:expect/expect.dart'; |
| 3 | 3 |
| 4 // This example illustrates a case we wish to do better in terms of inlining and | 4 // This example illustrates a case we wish to do better in terms of inlining and |
| 5 // code generation. | 5 // code generation. |
| 6 // | 6 // |
| 7 // Today this function is compiled without inlining Wrapper.[], JSArray.[] and | 7 // Naively this function would be compiled without inlining Wrapper.[], |
| 8 // Wrapper.[]= because: | 8 // JSArray.[] and Wrapper.[]= because: |
| 9 // JSArray.[] is too big (14 nodes) | 9 // JSArray.[] is too big (14 nodes) |
| 10 // Wrapper.[] is too big if we force inlining of JSArray (15 nodes) | 10 // Wrapper.[] is too big if we force inlining of JSArray (15 nodes) |
| 11 // Wrapper.[]= is even bigger (46 nodes) | 11 // Wrapper.[]= is even bigger (46 nodes) |
| 12 // | 12 // |
| 13 // See #25478 for ideas on how to make this better. | 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. |
| 14 @NoInline() | 17 @NoInline() |
| 15 test(data, x) { | 18 test(data, x) { |
| 16 data[x + 1] = data[x]; | 19 data[x + 1] = data[x]; |
| 17 } | 20 } |
| 18 | 21 |
| 19 main() { | 22 main() { |
| 20 var wrapper = new Wrapper(); | 23 var wrapper = new Wrapper(); |
| 21 wrapper[33] = wrapper[1]; // make Wrapper.[]= and [] used more than once. | 24 wrapper[33] = wrapper[1]; // make Wrapper.[]= and [] used more than once. |
| 22 print(test(new Wrapper(), int.parse('2'))); | 25 print(test(new Wrapper(), int.parse('2'))); |
| 23 } | 26 } |
| 24 | 27 |
| 25 class Wrapper { | 28 class Wrapper { |
| 26 final List arr = <bool>[true, false, false, true]; | 29 final List arr = <bool>[true, false, false, true]; |
| 27 operator[](int i) => this.arr[i]; | 30 operator[](int i) => this.arr[i]; |
| 28 operator[]=(int i, v) { | 31 operator[]=(int i, v) { |
| 29 if (i > arr.length - 1) arr.length = i + 1; | 32 if (i > arr.length - 1) arr.length = i + 1; |
| 30 return arr[i] = v; | 33 return arr[i] = v; |
| 31 } | 34 } |
| 32 } | 35 } |
| OLD | NEW |