Skip to content
Snippets Groups Projects
Commit 486cda78 authored by Lukas Stadler's avatar Lukas Stadler
Browse files

move builtin cache to RBuiltinPackages

parent 32305f34
Branches
No related tags found
No related merge requests found
......@@ -134,10 +134,15 @@ public final class RBuiltinPackages implements RBuiltinLookup {
}
}
/**
* Global builtin cache.
*/
private static final HashMap<Object, RFunction> cachedBuiltinFunctions = new HashMap<>();
@Override
public RFunction lookupBuiltin(String methodName) {
CompilerAsserts.neverPartOfCompilation();
RFunction function = RContext.getCachedBuiltin(methodName);
RFunction function = cachedBuiltinFunctions.get(methodName);
if (function != null) {
return function;
}
......@@ -152,7 +157,9 @@ public final class RBuiltinPackages implements RBuiltinLookup {
private static RFunction createFunction(RBuiltinFactory builtinFactory, String methodName) {
try {
RootCallTarget callTarget = RBuiltinNode.createArgumentsCallTarget(builtinFactory);
return RContext.cacheBuiltin(methodName, RDataFactory.createFunction(builtinFactory.getName(), callTarget, builtinFactory, REnvironment.baseEnv().getFrame(), false));
RFunction function = RDataFactory.createFunction(builtinFactory.getName(), callTarget, builtinFactory, REnvironment.baseEnv().getFrame(), false);
cachedBuiltinFunctions.put(methodName, function);
return function;
} catch (Throwable t) {
throw new RuntimeException("error while creating builtin " + methodName + " / " + builtinFactory, t);
}
......
......@@ -168,11 +168,6 @@ public final class RContext extends ExecutionContext {
}
}
/**
* Builtin cache. Valid across all contexts.
*/
private static final HashMap<Object, RFunction> cachedBuiltinFunctions = new HashMap<>();
private final ContextInfo info;
private final Engine engine;
......@@ -474,15 +469,6 @@ public final class RContext extends ExecutionContext {
return builtinLookup.lookupBuiltinDescriptor(name);
}
public static RFunction cacheBuiltin(Object key, RFunction function) {
cachedBuiltinFunctions.put(key, function);
return function;
}
public static RFunction getCachedBuiltin(Object key) {
return cachedBuiltinFunctions.get(key);
}
public RCmdOptions getOptions() {
return info.getOptions();
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment