Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(393)

Unified Diff: runtime/lib/mirrors_impl.dart

Issue 20216002: Make ClassMirror.typeVariables lazy and convert dependencies to native code. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: runtime/lib/mirrors_impl.dart
diff --git a/runtime/lib/mirrors_impl.dart b/runtime/lib/mirrors_impl.dart
index 4b5b660775dcb475faf5b152f7da1b504f1f811d..b4fe5557ea0a898b184b53c2bdf17ff386fbb3e5 100644
--- a/runtime/lib/mirrors_impl.dart
+++ b/runtime/lib/mirrors_impl.dart
@@ -4,6 +4,8 @@
// VM-specific implementation of the dart:mirrors library.
+import "dart:collection";
+
// These values are allowed to be passed directly over the wire.
bool _isSimpleValue(var value) {
return (value == null || value is num || value is String || value is bool);
@@ -401,11 +403,9 @@ class _LocalClassMirrorImpl extends _LocalObjectMirrorImpl
this._superclass,
this._superinterfaces,
this._defaultFactory,
- Map<String, Mirror> constructors,
- Map<String, Mirror> typeVariables)
+ Map<String, Mirror> constructors)
: this._simpleName = _s(simpleName),
this.constructors = _convertStringToSymbolMap(constructors),
- this.typeVariables = _convertStringToSymbolMap(typeVariables),
super(reflectee);
Symbol _simpleName;
@@ -528,7 +528,19 @@ class _LocalClassMirrorImpl extends _LocalObjectMirrorImpl
}
Map<Symbol, MethodMirror> constructors;
- Map<Symbol, TypeVariableMirror> typeVariables;
+
+ Map<Symbol, TypeVariableMirror> _typeVariables = null;
+ Map<Symbol, TypeVariableMirror> get typeVariables {
+ if (_typeVariables == null) {
+ List params = _ClassMirror_type_variables(_reflectee);
+ _typeVariables = new LinkedHashMap<Symbol, TypeVariableMirror>();
+ for (var i = 0; i < params.length; i += 2) {
+ _typeVariables[new Symbol(params[i])] =
+ new _LocalTypeVariableMirrorImpl(params[i + 1], params[0], this);
siva 2013/07/26 22:10:34 params[i] instead of params[0] (looks like we are
Michael Lippautz (Google) 2013/07/26 23:30:07 Done. I also added some tests do cover these thing
+ }
+ }
+ return _typeVariables;
+ }
Map<Symbol, TypeMirror> get typeArguments {
throw new UnimplementedError(
@@ -606,6 +618,9 @@ class _LocalClassMirrorImpl extends _LocalObjectMirrorImpl
static _invokeConstructor(reflectee, constructorName, positionalArguments)
native 'ClassMirror_invokeConstructor';
+
+ static _ClassMirror_type_variables(reflectee)
+ native "ClassMirror_type_variables";
}
class _LazyFunctionTypeMirror {
@@ -633,7 +648,6 @@ class _LocalFunctionTypeMirrorImpl extends _LocalClassMirrorImpl
new _LazyTypeMirror('dart:core', 'Object'),
[ new _LazyTypeMirror('dart:core', 'Function') ],
null,
- const {},
const {});
Map<Symbol, Mirror> get members => new Map<Symbol,Mirror>();
@@ -647,6 +661,7 @@ class _LocalFunctionTypeMirrorImpl extends _LocalClassMirrorImpl
}
final List<ParameterMirror> parameters;
+ final Map<Symbol, TypeVariableMirror> typeVariables = const {};
String toString() => "FunctionTypeMirror on '${_n(simpleName)}'";
}
@@ -654,7 +669,7 @@ class _LocalFunctionTypeMirrorImpl extends _LocalClassMirrorImpl
abstract class _LocalDeclarationMirrorImpl extends _LocalMirrorImpl
implements DeclarationMirror {
_LocalDeclarationMirrorImpl(this._reflectee);
- final _MirrorReference _reflectee;
+ final _reflectee;
List<InstanceMirror> get metadata {
// Get the metadata objects, convert them into InstanceMirrors using
@@ -680,8 +695,7 @@ class _LocalTypeVariableMirrorImpl extends _LocalDeclarationMirrorImpl
implements TypeVariableMirror {
_LocalTypeVariableMirrorImpl(reflectee,
String simpleName,
- this._owner,
- this._upperBound)
+ this._owner)
: this.simpleName = _s(simpleName),
super(reflectee);
@@ -697,6 +711,10 @@ class _LocalTypeVariableMirrorImpl extends _LocalDeclarationMirrorImpl
var _owner;
DeclarationMirror get owner {
+ if (_owner == null) {
+ _owner = _LocalTypeVariableMirror_owner(_reflectee);
+ }
+ // TODO(11897): This will go away, as soon as lazy mirrors go away.
if (_owner is! Mirror) {
_owner = _owner.resolve(mirrors);
}
@@ -712,10 +730,10 @@ class _LocalTypeVariableMirrorImpl extends _LocalDeclarationMirrorImpl
'TypeVariableMirror.location is not implemented');
}
- var _upperBound;
+ TypeMirror _upperBound = null;
TypeMirror get upperBound {
- if (_upperBound is! Mirror) {
- _upperBound = _upperBound.resolve(mirrors);
+ if (_upperBound == null) {
+ _upperBound = _LocalTypeVariableMirror_upper_bound(_reflectee);
}
return _upperBound;
}
@@ -726,6 +744,12 @@ class _LocalTypeVariableMirrorImpl extends _LocalDeclarationMirrorImpl
}
String toString() => "TypeVariableMirror on '${_n(simpleName)}'";
+
+ static DeclarationMirror _LocalTypeVariableMirror_owner(reflectee)
+ native "LocalTypeVariableMirror_owner";
+
+ static TypeMirror _LocalTypeVariableMirror_upper_bound(reflectee)
+ native "LocalTypeVariableMirror_upper_bound";
}

Powered by Google App Engine
This is Rietveld 408576698