You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@hbase.apache.org by "stack (JIRA)" <ji...@apache.org> on 2017/01/26 00:01:26 UTC

[jira] [Updated] (HBASE-17512) Optimize ServerName.parsePort() to reduce objects creation

     [ https://issues.apache.org/jira/browse/HBASE-17512?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

stack updated HBASE-17512:
--------------------------
    Assignee: Samuel David Glover

> Optimize ServerName.parsePort() to reduce objects creation
> ----------------------------------------------------------
>
>                 Key: HBASE-17512
>                 URL: https://issues.apache.org/jira/browse/HBASE-17512
>             Project: HBase
>          Issue Type: Bug
>    Affects Versions: 1.2.4
>            Reporter: Jean-Marc Spaggiari
>            Assignee: Samuel David Glover
>            Priority: Minor
>              Labels: beginner
>
> ServerName.parsePort() calls the split method on a string. This string format is like "www.example.org,1234,1212121212" where we try to get only 1234. Each time the split() method is called, it creates 4 objets. 3 strings and an array. And we just us one of those strings.
> This this method is called in a single place. In the constructor:
> {code}
>   private ServerName(final String serverName) {
>     this(parseHostname(serverName), parsePort(serverName),
>       parseStartcode(serverName));
>   }
> {code}
> So parsePort creates 3 string. Te hostname, the port, the startcode, but returns only the port, while we call 2 other methods to redo the exact same work.
> This constructor is called only there:
> {code}
>   /**
>    * Retrieve an instance of ServerName.
>    * Callers should use the equals method to compare returned instances, though we may return
>    * a shared immutable object as an internal optimization.
>    */
>   public static ServerName valueOf(final String serverName) {
>     return new ServerName(serverName);
>   }
> {code}
> and this is called here and there. Not intensively, but still, should be cleaned.
> Instead of using split, something like this might do better:
> {code}
>   public static int parsePort(final String serverName) {
>     int indexStart = serverName.indexOf(SERVERNAME_SEPARATOR);
>     int indexStop = serverName.lastIndexOf(SERVERNAME_SEPARATOR);
>     return Integer.parseInt(serverName.substring(indexStart + 1, indexStop));
>   }
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)