Details
-
Bug
-
Status: Open
-
Minor
-
Resolution: Unresolved
-
1.2.4
-
None
-
None
Description
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:
private ServerName(final String serverName) { this(parseHostname(serverName), parsePort(serverName), parseStartcode(serverName)); }
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:
/** * 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); }
and this is called here and there. Not intensively, but still, should be cleaned.
Instead of using split, something like this might do better:
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)); }