You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@hbase.apache.org by "Ted Yu (JIRA)" <ji...@apache.org> on 2018/03/15 15:58:00 UTC

[jira] [Commented] (HBASE-20209) Do Not Use Both Map containsKey and get Methods

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

Ted Yu commented on HBASE-20209:
--------------------------------

w.r.t. using {{get}} method, there should be other places in the code base where similar change is applicable.

Can you do some search and apply the change ?

Thanks

> Do Not Use Both Map containsKey and get Methods
> -----------------------------------------------
>
>                 Key: HBASE-20209
>                 URL: https://issues.apache.org/jira/browse/HBASE-20209
>             Project: HBase
>          Issue Type: Improvement
>          Components: hbase
>    Affects Versions: 2.0.0
>            Reporter: BELUGA BEHR
>            Assignee: BELUGA BEHR
>            Priority: Trivial
>         Attachments: HBASE-20209.1.patch
>
>
> {code:title=ReplicationSink.java}
>         String tableName = table.getNameWithNamespaceInclAsString();
>         if (bulkLoadHFileMap.containsKey(tableName)) {
>           List<Pair<byte[], List<String>>> familyHFilePathsList = bulkLoadHFileMap.get(tableName);
>           boolean foundFamily = false;
>           for (int i = 0; i < familyHFilePathsList.size(); i++) {
>             Pair<byte[], List<String>> familyHFilePathsPair = familyHFilePathsList.get(i);
>             if (Bytes.equals(familyHFilePathsPair.getFirst(), family)) {
>               // Found family already present, just add the path to the existing list
>               familyHFilePathsPair.getSecond().add(pathToHfileFromNS);
>               foundFamily = true;
>               break;
>             }
>           }
> {code}
> I propose that this code does not use the Map methods _containsKey_ *and* _get_.  Simply use the _get_ method once and check a _null_ return value to check for existence.  Saves a trip to the Map data structure for each call.  Also, use enhanced for loop.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)