| OLD | NEW |
| (Empty) | |
| 1 library angular.perf.mirror; |
| 2 |
| 3 import '_perf.dart'; |
| 4 import 'dart:mirrors'; |
| 5 |
| 6 main() { |
| 7 var c = new Obj(1); |
| 8 InstanceMirror im = reflect(c); |
| 9 Symbol symbol = new Symbol('a'); |
| 10 Watch head = new Watch(); |
| 11 Watch current = head; |
| 12 for(var i=1; i < 10000; i++) { |
| 13 Watch next = new Watch(); |
| 14 current = (current.next = new Watch()); |
| 15 } |
| 16 |
| 17 var dirtyCheck = () { |
| 18 Watch current = head; |
| 19 while(current != null) { |
| 20 if (!identical(current.lastValue, current.im.getField(current.symbol).refl
ectee)) { |
| 21 throw "We should not get here"; |
| 22 } |
| 23 current = current.next; |
| 24 } |
| 25 }; |
| 26 |
| 27 var dirtyCheckFn = () { |
| 28 Watch current = head; |
| 29 while(current != null) { |
| 30 if (!identical(current.lastValue, current.getter(current.object))) { |
| 31 throw "We should not get here"; |
| 32 } |
| 33 current = current.next; |
| 34 } |
| 35 }; |
| 36 |
| 37 time('fieldRead', () => im.getField(symbol).reflectee ); |
| 38 time('Object.observe', dirtyCheck); |
| 39 time('Object.observe fn()', dirtyCheckFn); |
| 40 } |
| 41 |
| 42 class Watch { |
| 43 dynamic lastValue = 1; |
| 44 Watch next; |
| 45 String location; |
| 46 dynamic object = new Obj(1); |
| 47 InstanceMirror im; |
| 48 Symbol symbol = new Symbol('a'); |
| 49 Function getter = (s) => s.a; |
| 50 |
| 51 Watch() { |
| 52 im = reflect(object); |
| 53 } |
| 54 } |
| 55 |
| 56 class Obj { |
| 57 var a; |
| 58 |
| 59 Obj(this.a); |
| 60 } |
| OLD | NEW |