From 4d87ba10c187c6576afe712c02d997f00261e951 Mon Sep 17 00:00:00 2001 From: nathan Date: Sun, 28 Jan 2018 14:16:11 +0100 Subject: [PATCH] Improve performance of get operations in Options --- src/dorkbox/network/dns/utils/Options.java | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/dorkbox/network/dns/utils/Options.java b/src/dorkbox/network/dns/utils/Options.java index 99e77c32..c6dcdc08 100644 --- a/src/dorkbox/network/dns/utils/Options.java +++ b/src/dorkbox/network/dns/utils/Options.java @@ -2,10 +2,10 @@ package dorkbox.network.dns.utils; -import java.util.HashMap; -import java.util.Map; import java.util.StringTokenizer; +import com.esotericsoftware.kryo.util.ObjectMap; + /** * Boolean options:
* bindttl - Print TTLs in BIND format
@@ -27,12 +27,12 @@ import java.util.StringTokenizer; public final class Options { - private static Map table; + private static ObjectMap table; static { try { refresh(); - } catch (SecurityException e) { + } catch (SecurityException ignored) { } } @@ -65,8 +65,9 @@ class Options { public static void set(String option) { if (table == null) { - table = new HashMap(); + table = new ObjectMap(); } + table.put(option.toLowerCase(), "true"); } @@ -76,7 +77,7 @@ class Options { public static void set(String option, String value) { if (table == null) { - table = new HashMap(); + table = new ObjectMap(); } table.put(option.toLowerCase(), value.toLowerCase()); } @@ -108,6 +109,7 @@ class Options { if (table == null) { return false; } + return (table.get(option.toLowerCase()) != null); } @@ -123,10 +125,11 @@ class Options { if (val > 0) { return (val); } - } catch (NumberFormatException e) { + } catch (NumberFormatException ignored) { } } - return (-1); + + return -1; } /** @@ -137,7 +140,7 @@ class Options { if (table == null) { return null; } + return ((String) table.get(option.toLowerCase())); } - }