Skip to content

Commit 5a5e7bc

Browse files
committed
Make less allocations
1 parent acb2459 commit 5a5e7bc

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/main/java/com/maxmind/db/Reader.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -235,14 +235,14 @@ public <T> Networks<T> networks(
235235
Class<T> typeParameterClass) throws
236236
InvalidNetworkException, ClosedDatabaseException, InvalidDatabaseException {
237237
try {
238-
InetAddress ipv4 = InetAddress.getByAddress(new byte[4]);
239-
InetAddress ipv6 = InetAddress.getByAddress(new byte[16]);
240-
Network ipAllV4 = new Network(ipv4, 0); // Mask 32.
241-
Network ipAllV6 = new Network(ipv6, 0); // Mask 128.
242-
243238
if (this.getMetadata().getIpVersion() == 6) {
239+
InetAddress ipv6 = InetAddress.getByAddress(new byte[16]);
240+
Network ipAllV6 = new Network(ipv6, 0); // Mask 128.
244241
return this.networksWithin(ipAllV6, includeAliasedNetworks, typeParameterClass);
245242
}
243+
244+
InetAddress ipv4 = InetAddress.getByAddress(new byte[4]);
245+
Network ipAllV4 = new Network(ipv4, 0); // Mask 32.
246246
return this.networksWithin(ipAllV4, includeAliasedNetworks, typeParameterClass);
247247
} catch (UnknownHostException e) {
248248
/* This is returned by getByAddress. This should never happen

0 commit comments

Comments
 (0)