[ 
https://issues.apache.org/jira/browse/HDFS-14799?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16927746#comment-16927746
 ] 

hemanthboyina commented on HDFS-14799:
--------------------------------------

[~ayushtkn] can you push the patch forward

> 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
>            Assignee: hemanthboyina
>            Priority: Minor
>              Labels: newbie, noob
>         Attachments: HDFS-14799.001.patch
>
>
> {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-issues-unsubscr...@hadoop.apache.org
For additional commands, e-mail: hdfs-issues-h...@hadoop.apache.org

Reply via email to