Michael Braun created CALCITE-7780:
--------------------------------------
Summary: Avoid redundant map lookups
Key: CALCITE-7780
URL: https://issues.apache.org/jira/browse/CALCITE-7780
Project: Calcite
Issue Type: Improvement
Reporter: Michael Braun
Several places look up the same map key two or three times in a row, where one
call to an existing Map method does the same job. For example,
HepPlanner#updateVertex:
if (mapDigestToVertex.get(oldKey) == vertex) {
mapDigestToVertex.remove(oldKey);
}
is Map#remove(key, value):
mapDigestToVertex.remove(oldKey, vertex);
The same shape occurs in a handful of other classes, replaced with the
corresponding single-lookup idiom: a get plus null check for containsKey
followed by get; putIfAbsent or computeIfAbsent for containsKey followed by
put; iteration over entrySet, with Map.Entry#setValue for in-place updates,
for iterating keySet and calling get per key.
Some sites are on per-row paths (AggregateNode#send, UncollectNode,
RexToLixTranslator's expression caches); the rest are planner and validator
code. No lambda introduced captures enclosing state.
No functional change. All values involved are non-null, so replacing
containsKey with a null check on get preserves behaviour.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)