Remove redundant hash lookups in PureFunctionIdentifier.
@@ -266,8 +266,13 @@ class PureFunctionIdentifier implements CompilerPass {
}
String name = NameBasedDefinitionProvider.getSimplifiedName(expression);
- if (name != null && functionInfoByName.containsKey(name)) {
- results.add(functionInfoByName.get(name));
+ FunctionInformation info = null;
+ if (name != null) {
+ info = functionInfoByName.get(name);
+ }
+
+ if (info != null) {
+ results.add(info);
} else {
return null;
}
@@ -304,10 +309,11 @@ class PureFunctionIdentifier implements CompilerPass {
} else {
// Unsupported function definition. Mark a global side effect here since we don't
// actually know anything about what's being defined.
- if (functionInfoByName.containsKey(name)) {
- functionInfoByName.get(name).setTaintsGlobalState();
- functionInfoByName.get(name).setFunctionThrows();
- functionInfoByName.get(name).setTaintsReturn();
+ FunctionInformation info = functionInfoByName.get(name);
+ if (info != null) {
+ info.setTaintsGlobalState();
+ info.setFunctionThrows();
+ info.setTaintsReturn();
} else {
functionInfoByName.put(name, unknownDefinitionFunction);
}
@@ -323,12 +329,10 @@ class PureFunctionIdentifier implements CompilerPass {
*/
private void addSupportedDefinition(DefinitionSite definitionSite, String name) {
for (Node function : unwrapCallableExpression(definitionSite.definition.getRValue())) {
- FunctionInformation functionInfo;
- if (functionInfoByName.containsKey(name)) {
- // This is a function name with multiple definitions!
- // Here we link this function definition to the existing FunctionInfo node.
- functionInfo = functionInfoByName.get(name);
- } else {
+ // A function may have multiple definitions.
+ // Link this function definition to the existing FunctionInfo node.
+ FunctionInformation functionInfo = functionInfoByName.get(name);
+ if (functionInfo == null) {
// Need to create a function info node.
functionInfo = new FunctionInformation();
functionInfo.graphNode = sideEffectGraph.createNode(functionInfo);
