diff options
author | Mike Lockwood <lockwood@android.com> | 2009-08-12 17:15:51 -0400 |
---|---|---|
committer | Mike Lockwood <lockwood@android.com> | 2009-08-12 17:20:41 -0400 |
commit | d1945950451220932f70bac83408c761dcba231f (patch) | |
tree | aa30b0fc77278bb67bd06de50e687c4c805580ef /core/java/android/os | |
parent | 444874049075a6f1a921555083881071a02fc955 (diff) | |
download | frameworks_base-d1945950451220932f70bac83408c761dcba231f.zip frameworks_base-d1945950451220932f70bac83408c761dcba231f.tar.gz frameworks_base-d1945950451220932f70bac83408c761dcba231f.tar.bz2 |
SystemProperties: eliminate unnecessary string allocation.
getInt(), getLong() and getBoolean() no longer allocate a temporary String object.
Signed-off-by: Mike Lockwood <lockwood@android.com>
Diffstat (limited to 'core/java/android/os')
-rw-r--r-- | core/java/android/os/SystemProperties.java | 40 |
1 files changed, 12 insertions, 28 deletions
diff --git a/core/java/android/os/SystemProperties.java b/core/java/android/os/SystemProperties.java index c3ae3c2..4a036ec 100644 --- a/core/java/android/os/SystemProperties.java +++ b/core/java/android/os/SystemProperties.java @@ -30,6 +30,9 @@ public class SystemProperties private static native String native_get(String key); private static native String native_get(String key, String def); + private static native int native_get_int(String key, int def); + private static native long native_get_long(String key, long def); + private static native boolean native_get_boolean(String key, boolean def); private static native void native_set(String key, String def); /** @@ -65,11 +68,10 @@ public class SystemProperties * @throws IllegalArgumentException if the key exceeds 32 characters */ public static int getInt(String key, int def) { - try { - return Integer.parseInt(get(key)); - } catch (NumberFormatException e) { - return def; + if (key.length() > PROP_NAME_MAX) { + throw new IllegalArgumentException("key.length > " + PROP_NAME_MAX); } + return native_get_int(key, def); } /** @@ -81,11 +83,10 @@ public class SystemProperties * @throws IllegalArgumentException if the key exceeds 32 characters */ public static long getLong(String key, long def) { - try { - return Long.parseLong(get(key)); - } catch (NumberFormatException e) { - return def; + if (key.length() > PROP_NAME_MAX) { + throw new IllegalArgumentException("key.length > " + PROP_NAME_MAX); } + return native_get_long(key, def); } /** @@ -102,27 +103,10 @@ public class SystemProperties * @throws IllegalArgumentException if the key exceeds 32 characters */ public static boolean getBoolean(String key, boolean def) { - String value = get(key); - // Deal with these quick cases first: not found, 0 and 1 - if (value.equals("")) { - return def; - } else if (value.equals("0")) { - return false; - } else if (value.equals("1")) { - return true; - // now for slower (and hopefully less common) cases - } else if (value.equalsIgnoreCase("n") || - value.equalsIgnoreCase("no") || - value.equalsIgnoreCase("false") || - value.equalsIgnoreCase("off")) { - return false; - } else if (value.equalsIgnoreCase("y") || - value.equalsIgnoreCase("yes") || - value.equalsIgnoreCase("true") || - value.equalsIgnoreCase("on")) { - return true; + if (key.length() > PROP_NAME_MAX) { + throw new IllegalArgumentException("key.length > " + PROP_NAME_MAX); } - return def; + return native_get_boolean(key, def); } /** |