Skip to content

Commit

Permalink
Avoid unnecessary calls to Collections.emptySet
Browse files Browse the repository at this point in the history
IntelliJ IDEA rewrote these Map manipulations to use Map.getOrDefault in
ways that always called Collections.emptySet even when no such empty set
was required.  I've manually replaced those with rewrites that avoid
unnecessary calls to Collections.emptySet in exchange for assuming that
the Maps never contain null values.
  • Loading branch information
liblit committed May 9, 2019
1 parent 4fb7af2 commit c6bd0c0
Showing 1 changed file with 4 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,14 @@ public CAstNode getTarget(CAstNode from, Object label) {
@Override
public Collection<Object> getTargetLabels(CAstNode from) {
Object node = CAstToNode.get(from);
return labelMap.getOrDefault(node, Collections.emptySet());
Set<Object> found = labelMap.get(node);
return found == null ? Collections.emptySet() : found;
}

@Override
public Set<Object> getSourceNodes(CAstNode to) {
return sourceMap.getOrDefault(CAstToNode.get(to), Collections.emptySet());
Set<Object> found = sourceMap.get(CAstToNode.get(to));
return found == null ? Collections.emptySet() : found;
}

@Override
Expand Down

0 comments on commit c6bd0c0

Please sign in to comment.