Skip to content

Commit

Permalink
Cache ModelElements for dynamic and Never
Browse files Browse the repository at this point in the history
  • Loading branch information
srawlins committed Jul 7, 2024
1 parent 6a02ffb commit 8a36b99
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions lib/src/model/model_element.dart
Original file line number Diff line number Diff line change
Expand Up @@ -204,13 +204,6 @@ abstract class ModelElement
e.kind == ElementKind.DYNAMIC ||
e.kind == ElementKind.NEVER);

if (e.kind == ElementKind.DYNAMIC) {
return Dynamic(e, packageGraph);
}
if (e.kind == ElementKind.NEVER) {
return NeverType(e, packageGraph);
}

Member? originalMember;
// TODO(jcollins-g): Refactor object model to instantiate 'ModelMembers'
// for members?
Expand All @@ -220,12 +213,21 @@ abstract class ModelElement
}

// Return the cached ModelElement if it exists.
var cachedModelElement = packageGraph.allConstructedModelElements[
ConstructedModelElementsKey(e, library, enclosingContainer)];
var key = ConstructedModelElementsKey(e, library, enclosingContainer);
var cachedModelElement = packageGraph.allConstructedModelElements[key];
if (cachedModelElement != null) {
return cachedModelElement;
}

if (e.kind == ElementKind.DYNAMIC) {
return packageGraph.allConstructedModelElements[key] =
Dynamic(e, packageGraph);
}
if (e.kind == ElementKind.NEVER) {
return packageGraph.allConstructedModelElements[key] =
NeverType(e, packageGraph);
}

var newModelElement = ModelElement._constructFromElementDeclaration(
e,
library,
Expand Down

0 comments on commit 8a36b99

Please sign in to comment.