Committed by
Gerrit Code Review
temporary fix for ONOS-1144: slow IPAddress.toString()
Change-Id: Ia7b9a71bb8c5b90dbc6256c35e8aa5a6567299c8
Showing
1 changed file
with
18 additions
and
8 deletions
... | @@ -331,15 +331,25 @@ public class IpAddress implements Comparable<IpAddress> { | ... | @@ -331,15 +331,25 @@ public class IpAddress implements Comparable<IpAddress> { |
331 | * @see java.lang.Object#toString() | 331 | * @see java.lang.Object#toString() |
332 | */ | 332 | */ |
333 | public String toString() { | 333 | public String toString() { |
334 | - InetAddress inetAddr = null; | 334 | + // FIXME InetAddress is super slow |
335 | - try { | 335 | + switch (version) { |
336 | - inetAddr = InetAddress.getByAddress(octets); | 336 | + case INET: |
337 | - } catch (UnknownHostException e) { | 337 | + return String.format("%d.%d.%d.%d", octets[0] & 0xff, |
338 | - // Should never happen | 338 | + octets[1] & 0xff, |
339 | - checkState(false, "Internal error: Ip6Address.toString()"); | 339 | + octets[2] & 0xff, |
340 | - return "[Invalid IP Address]"; | 340 | + octets[3] & 0xff); |
341 | + case INET6: | ||
342 | + default: | ||
343 | + InetAddress inetAddr = null; | ||
344 | + try { | ||
345 | + inetAddr = InetAddress.getByAddress(octets); | ||
346 | + } catch (UnknownHostException e) { | ||
347 | + // Should never happen | ||
348 | + checkState(false, "Internal error: Ip6Address.toString()"); | ||
349 | + return "[Invalid IP Address]"; | ||
350 | + } | ||
351 | + return InetAddresses.toAddrString(inetAddr); | ||
341 | } | 352 | } |
342 | - return InetAddresses.toAddrString(inetAddr); | ||
343 | } | 353 | } |
344 | 354 | ||
345 | /** | 355 | /** | ... | ... |
-
Please register or login to post a comment