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

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: Get rid of TypeVariableMirror dependency 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 acd568d6e6d65f4c8eacdbf0b1cba6e4cf605f02..8919165c4dffe7cd7a6ddf820c31497f010d0921 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,17 @@ class _LocalClassMirrorImpl extends _LocalObjectMirrorImpl
}
Map<Symbol, MethodMirror> constructors;
- Map<Symbol, TypeVariableMirror> typeVariables;
+
+ Map<Symbol, TypeVariableMirror> _typeVariables = null;
+ Map<Symbol, TypeVariableMirror> get typeVariables {
Michael Lippautz (Google) 2013/07/25 20:17:57 Future API may return a List here. We already get
+ if (_typeVariables == null) {
+ List<TypeVariableMirror> result = _ClassMirror_type_variables(
+ _reflectee, this);
+ _typeVariables = new LinkedHashMap<Symbol, TypeVariableMirror>
+ .fromIterable(result, key: (e) => e.simpleName);
+ }
+ return _typeVariables;
+ }
Map<Symbol, TypeMirror> get typeArguments {
throw new UnimplementedError(
@@ -606,6 +616,9 @@ class _LocalClassMirrorImpl extends _LocalObjectMirrorImpl
static _invokeConstructor(reflectee, constructorName, positionalArguments)
native 'ClassMirror_invokeConstructor';
+
+ static _ClassMirror_type_variables(reflectee, mirror)
+ native "ClassMirror_type_variables";
}
class _LazyFunctionTypeMirror {
@@ -633,7 +646,6 @@ class _LocalFunctionTypeMirrorImpl extends _LocalClassMirrorImpl
new _LazyTypeMirror('dart:core', 'Object'),
[ new _LazyTypeMirror('dart:core', 'Function') ],
null,
- const {},
const {});
Map<Symbol, Mirror> get members => const {};
@@ -647,6 +659,7 @@ class _LocalFunctionTypeMirrorImpl extends _LocalClassMirrorImpl
}
final List<ParameterMirror> parameters;
+ final Map<Symbol, TypeVariableMirror> typeVariables = const {};
String toString() => "FunctionTypeMirror on '${_n(simpleName)}'";
}
@@ -680,8 +693,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 +709,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 +728,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 +742,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