Skip to content
This repository was archived by the owner on Feb 22, 2018. It is now read-only.

Commit cc0e095

Browse files
pavelgjjbdeboer
authored andcommitted
hack(mirrors): A hack for slow reflectClass
1 parent e762425 commit cc0e095

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

lib/mirrors.dart

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
part of angular;
22

3+
Map<Type, ClassMirror> _reflectionCache = new Map<Type, ClassMirror>();
4+
5+
// A hack for slow reflectClass.
6+
ClassMirror fastReflectClass(Type type) {
7+
ClassMirror reflectee = _reflectionCache[type];
8+
if (reflectee == null) {
9+
reflectee = reflectClass(type);
10+
_reflectionCache[type] = reflectee;
11+
}
12+
return reflectee;
13+
}
14+
315
/**
416
* A set of functions which build on top of dart:mirrors making them
517
* easier to use.
@@ -8,7 +20,7 @@ part of angular;
820
// Return the value of a type's static field or null if it is not defined.
921
reflectStaticField(Type type, String field) {
1022
Symbol fieldSym = new Symbol(field);
11-
var reflection = reflectClass(type);
23+
var reflection = fastReflectClass(type);
1224
if (!reflection.members.containsKey(fieldSym)) return null;
1325
if (!reflection.members[fieldSym].isStatic) return null;
1426

0 commit comments

Comments
 (0)