David Mollitor created HDFS-14799: ------------------------------------- Summary: Do Not Call Map containsKey In Conjunction with get Key: HDFS-14799 URL: https://issues.apache.org/jira/browse/HDFS-14799 Project: Hadoop HDFS Issue Type: Improvement Components: namenode Affects Versions: 3.2.0 Reporter: David Mollitor
{code:java|title=InvalidateBlocks.java} private final Map<DatanodeInfo, LightWeightHashSet<Block>> nodeToBlocks = new HashMap<>(); private final Map<DatanodeInfo, LightWeightHashSet<Block>> nodeToECBlocks = new HashMap<>(); ... private LightWeightHashSet<Block> getBlocksSet(final DatanodeInfo dn) { if (nodeToBlocks.containsKey(dn)) { return nodeToBlocks.get(dn); } return null; } private LightWeightHashSet<Block> getECBlocksSet(final DatanodeInfo dn) { if (nodeToECBlocks.containsKey(dn)) { return nodeToECBlocks.get(dn); } return null; } {code} There is no need to check for {{containsKey}} here since a call to {{get}} will already return 'null' if the key is not there. This just adds overhead of having to dive into the Map twice to get the value. {code} private LightWeightHashSet<Block> getECBlocksSet(final DatanodeInfo dn) { return nodeToECBlocks.get(dn); } {code} -- This message was sent by Atlassian Jira (v8.3.2#803003) --------------------------------------------------------------------- To unsubscribe, e-mail: hdfs-dev-unsubscr...@hadoop.apache.org For additional commands, e-mail: hdfs-dev-h...@hadoop.apache.org