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 8, 2024
1 parent 22417c8 commit f940c5f
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 @@ -205,13 +205,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 @@ -221,12 +214,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 f940c5f

Please sign in to comment.