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

Another hack for slow reflectClass #3

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion lib/mirrors.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
part of angular;

Map<Type, ClassMirror> _reflectionCache = new Map<Type, ClassMirror>();

// A hack for slow reflectClass.
ClassMirror fastReflectClass(Type type) {
ClassMirror reflectee = _reflectionCache[type];
if (reflectee == null) {
reflectee = reflectClass(type);
_reflectionCache[type] = reflectee;
}
return reflectee;
}

/**
* A set of functions which build on top of dart:mirrors making them
* easier to use.
Expand All @@ -8,7 +20,7 @@ part of angular;
// Return the value of a type's static field or null if it is not defined.
reflectStaticField(Type type, String field) {
Symbol fieldSym = new Symbol(field);
var reflection = reflectClass(type);
var reflection = fastReflectClass(type);
if (!reflection.members.containsKey(fieldSym)) return null;
if (!reflection.members[fieldSym].isStatic) return null;

Expand Down