Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cache ModelElements for dynamic and Never #3815

Merged
merged 1 commit into from
Jul 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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