mirror of
https://github.com/enso-org/enso.git
synced 2024-11-23 16:18:23 +03:00
Dedicated Module.containsUUID method with a cache (#5945)
Fixes #5781 by caching all UUIDs in each module in a `Map`.
This commit is contained in:
parent
d77d08358e
commit
e666d797c5
@ -338,13 +338,7 @@ public class EnsoContext {
|
||||
*/
|
||||
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();
|
||||
}
|
||||
|
||||
|
@ -17,8 +17,10 @@ import com.oracle.truffle.api.source.SourceSection;
|
||||
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;
|
||||
|
||||
@ -93,6 +95,7 @@ public final class Module implements TruffleObject {
|
||||
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;
|
||||
@ -285,6 +288,7 @@ public final class Module implements TruffleObject {
|
||||
};
|
||||
var copy = this.ir.mapExpressions(fn);
|
||||
this.ir = copy;
|
||||
this.uuidsMap = null;
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -407,6 +411,28 @@ public final class Module implements TruffleObject {
|
||||
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;
|
||||
@ -434,6 +460,7 @@ public final class Module implements TruffleObject {
|
||||
*/
|
||||
public void unsafeSetIr(IR.Module ir) {
|
||||
this.ir = ir;
|
||||
this.uuidsMap = null;
|
||||
}
|
||||
|
||||
/** @return the runtime scope of this module. */
|
||||
|
Loading…
Reference in New Issue
Block a user