Skip to content

Commit

Permalink
Avoid creating a bazillion lambdas, they create a lot of unnecessary …
Browse files Browse the repository at this point in the history
…garbage.

PiperOrigin-RevId: 608602813
Change-Id: I558b7ec39b18b65ac86a694024c6ef6393236875
  • Loading branch information
meisterT authored and copybara-github committed Feb 20, 2024
1 parent 0e3544f commit 1ef1355
Showing 1 changed file with 15 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -341,23 +341,21 @@ private VariableValue lookupVariable(
structuredVariableCache = Maps.newConcurrentMap();
}

Object variableOrError =
structuredVariableCache.computeIfAbsent(
name,
n -> {
try {
VariableValue variable = getStructureVariable(n, throwOnMissingVariable, expander);
return variable != null ? variable : NULL_MARKER;
} catch (ExpansionException e) {
if (throwOnMissingVariable) {
return e.getMessage();
} else {
throw new IllegalStateException(
"Should not happen - call to getStructuredVariable threw when asked not to.",
e);
}
}
});
Object variableOrError = structuredVariableCache.get(name);
if (variableOrError == null) {
try {
VariableValue variable = getStructureVariable(name, throwOnMissingVariable, expander);
variableOrError = variable != null ? variable : NULL_MARKER;
} catch (ExpansionException e) {
if (throwOnMissingVariable) {
variableOrError = e.getMessage();
} else {
throw new IllegalStateException(
"Should not happen - call to getStructuredVariable threw when asked not to.", e);
}
}
structuredVariableCache.putIfAbsent(name, variableOrError);
}

if (variableOrError instanceof VariableValue) {
return (VariableValue) variableOrError;
Expand Down

0 comments on commit 1ef1355

Please sign in to comment.