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

Unified Diff: reflectable/lib/src/mirrors_unimpl.dart

Issue 1284423004: Initializes _data in constructor (Closed) Base URL: https://github.com/dart-lang/reflectable.git@master
Patch Set: Created 5 years, 4 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: reflectable/lib/src/mirrors_unimpl.dart
diff --git a/reflectable/lib/src/mirrors_unimpl.dart b/reflectable/lib/src/mirrors_unimpl.dart
index 130c6b31fa07c31b3f9ae0da8b63f887f3504329..7dc5e65875808bb0a722362ea110ab6ed32f16a4 100644
--- a/reflectable/lib/src/mirrors_unimpl.dart
+++ b/reflectable/lib/src/mirrors_unimpl.dart
@@ -104,27 +104,24 @@ Map<Reflectable, ReflectorData> data =
"Did you forget to add the main file to the "
"reflectable transformer's entry_points in pubspec.yaml?");
-abstract class _DataCaching {
- // TODO(eernst) clarify: When we have some substantial pieces of code using
- // reflectable, perform some experiments to detect how useful it is to have
- // this kind of caching.
+abstract class _DataCachingMirror {
+ /// The reflector which represents the mirror system that this
+ /// mirror belongs to.
+ final ReflectableImpl _reflector;
- ReflectorData _dataCache;
- ReflectableImpl get _reflector;
+ /// Reflector data associated with this mirror.
+ final ReflectorData _data;
- ReflectorData get _data {
- if (_dataCache == null) {
- _dataCache = data[_reflector];
- }
- return _dataCache;
- }
+ _DataCachingMirror(ReflectableImpl reflector)
+ : _reflector = reflector,
+ _data = data[reflector];
}
-class _InstanceMirrorImpl extends _DataCaching implements InstanceMirror {
- final ReflectableImpl _reflector;
+class _InstanceMirrorImpl extends _DataCachingMirror implements InstanceMirror {
final Object reflectee;
- _InstanceMirrorImpl(this.reflectee, this._reflector) {
+ _InstanceMirrorImpl(this.reflectee, ReflectableImpl reflector)
+ : super(reflector) {
_type = _data.classMirrorForType(reflectee.runtimeType);
if (_type == null) {
throw new NoSuchCapabilityError(
@@ -226,11 +223,7 @@ MethodMirror _variableToSetterMirror(VariableMirrorImpl variableMirror) {
[]);
}
-class ClassMirrorImpl extends _DataCaching implements ClassMirror {
- /// The reflector which represents the mirror system that this
- /// mirror belongs to.
- final ReflectableImpl _reflector;
-
+class ClassMirrorImpl extends _DataCachingMirror implements ClassMirror {
/// The index of this mirror in the [ReflectorData.classMirrors] table.
/// Also this is the index of the Type of the reflected class in
/// [ReflectorData.types].
@@ -263,7 +256,7 @@ class ClassMirrorImpl extends _DataCaching implements ClassMirror {
this.simpleName,
this.qualifiedName,
this._classIndex,
- this._reflector,
+ ReflectableImpl reflector,
this._declarationIndices,
this._instanceMemberIndices,
this._superclassIndex,
@@ -272,7 +265,8 @@ class ClassMirrorImpl extends _DataCaching implements ClassMirror {
this.constructors,
metadata)
: _metadata =
- (metadata == null) ? null : new UnmodifiableListView(metadata);
+ (metadata == null) ? null : new UnmodifiableListView(metadata),
+ super(reflector);
ClassMirror get superclass {
if (_superclassIndex == null) return null;
@@ -452,7 +446,7 @@ class ClassMirrorImpl extends _DataCaching implements ClassMirror {
// operations.
}
-class MethodMirrorImpl extends _DataCaching implements MethodMirror {
+class MethodMirrorImpl extends _DataCachingMirror implements MethodMirror {
/// An encoding of the attributes and kind of this mirror.
final int _descriptor;
@@ -466,18 +460,16 @@ class MethodMirrorImpl extends _DataCaching implements MethodMirror {
/// of this method.
final List<int> _parameterIndices;
- /// The [Reflectable] associated with this mirror.
- final ReflectableImpl _reflector;
-
/// A cache of the metadata of the mirrored method. The empty list means
/// no metadata, null means that [_reflector] does not have
/// [metadataCapability].
final List<Object> _metadata;
MethodMirrorImpl(this._name, this._descriptor, this._ownerIndex,
- this._parameterIndices, this._reflector, List<Object> metadata)
+ this._parameterIndices, ReflectableImpl reflector, List<Object> metadata)
: _metadata =
- (metadata == null) ? null : new UnmodifiableListView(metadata);
+ (metadata == null) ? null : new UnmodifiableListView(metadata),
+ super(reflector);
int get kind => constants.kindFromEncoding(_descriptor);
@@ -569,18 +561,18 @@ class MethodMirrorImpl extends _DataCaching implements MethodMirror {
String toString() => "MethodMirror($_name)";
}
-abstract class VariableMirrorBase extends _DataCaching
+abstract class VariableMirrorBase extends _DataCachingMirror
implements VariableMirror {
final String _name;
final int _descriptor;
final int _ownerIndex;
- final ReflectableImpl _reflector;
final List<Object> _metadata;
VariableMirrorBase(this._name, this._descriptor, this._ownerIndex,
- this._reflector, List<Object> metadata)
+ ReflectableImpl reflector, List<Object> metadata)
: _metadata =
- (metadata == null) ? null : new UnmodifiableListView(metadata);
+ (metadata == null) ? null : new UnmodifiableListView(metadata),
+ super(reflector);
int get kind => constants.kindFromEncoding(_descriptor);
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698