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

Dedicated Module.containsUUID method with a cache #5945

Merged
merged 4 commits into from
Mar 15, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -338,13 +338,7 @@ public Optional<Module> findModule(String moduleName) {
*/
public Optional<Module> findModuleByExpressionId(UUID expressionId) {
return getTopScope().getModules().stream()
.filter(
module ->
module.getIr() != null
&& module
.getIr()
.preorder()
.exists(ir -> ir.getExternalId().contains(expressionId)))
.filter(m -> m.containsUUID(expressionId))
.findFirst();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@
import java.io.File;
import java.io.IOException;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.WeakHashMap;
import java.util.logging.Level;

Expand Down Expand Up @@ -93,6 +95,7 @@ public boolean isBefore(CompilationStage stage) {
private CompilationStage compilationStage = CompilationStage.INITIAL;
private boolean isIndexed = false;
private IR.Module ir;
private Map<UUID, IR> uuidsMap;
private QualifiedName name;
private final ModuleCache cache;
private boolean wasLoadedFromCache;
Expand Down Expand Up @@ -285,6 +288,7 @@ public IR.Expression apply(IR.Expression v1) {
};
var copy = this.ir.mapExpressions(fn);
this.ir = copy;
this.uuidsMap = null;
return;
}
}
Expand Down Expand Up @@ -407,6 +411,28 @@ public IR.Module getIr() {
return ir;
}

public boolean containsUUID(UUID id) {
var map = uuidsMap;
if (map == null) {
var newMap = new HashMap<UUID, IR>();
var localIr = getIr();
if (localIr != null) {
localIr
.preorder()
.foreach(
(v1) -> {
if (v1.getExternalId().isDefined()) {
newMap.put(v1.getExternalId().get(), v1);
}
return null;
});
}
uuidsMap = newMap;
map = newMap;
}
return map.containsKey(id);
}

/** @return the current compilation stage of this module. */
public CompilationStage getCompilationStage() {
return compilationStage;
Expand Down Expand Up @@ -434,6 +460,7 @@ public void unsafeSetCompilationStage(CompilationStage compilationStage) {
*/
public void unsafeSetIr(IR.Module ir) {
this.ir = ir;
this.uuidsMap = null;
}

/** @return the runtime scope of this module. */
Expand Down