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