diff options
author | Ali Utku Selen <aliutku.selen@sonyericsson.com> | 2011-02-09 14:11:22 +0100 |
---|---|---|
committer | Jean-Baptiste Queru <jbq@google.com> | 2012-08-10 09:24:42 -0700 |
commit | 0a12018e4cd6eaaeaec795f6b2af4499fe3a8bcd (patch) | |
tree | 72a4fe97b6d82ea1477323f6d4d1fff9688e0e80 /core/java/android/hardware | |
parent | 37548994e69292932e9e2fafb7cba6c53e3a2bcd (diff) | |
download | frameworks_base-0a12018e4cd6eaaeaec795f6b2af4499fe3a8bcd.zip frameworks_base-0a12018e4cd6eaaeaec795f6b2af4499fe3a8bcd.tar.gz frameworks_base-0a12018e4cd6eaaeaec795f6b2af4499fe3a8bcd.tar.bz2 |
Change StringTokenizer to TextUtils.StringSplitter
Replacing StringTokenizer to TextUtils.StringSplitter,
since TextUtils.StringSplitter is more suitable for basic splitting tasks.
Also increased initial values for HashMap and StringBuilders to avoid
unnecessary buffer enlargement operations. This improves the performance
of these operations.
Change-Id: If9a5b68e6596ba9a6d29597876b6164ef34b57ac
Diffstat (limited to 'core/java/android/hardware')
-rw-r--r-- | core/java/android/hardware/Camera.java | 51 |
1 files changed, 26 insertions, 25 deletions
diff --git a/core/java/android/hardware/Camera.java b/core/java/android/hardware/Camera.java index 4d9077f..829620b 100644 --- a/core/java/android/hardware/Camera.java +++ b/core/java/android/hardware/Camera.java @@ -26,6 +26,7 @@ import android.os.Handler; import android.os.Looper; import android.os.Message; import android.util.Log; +import android.text.TextUtils; import android.view.Surface; import android.view.SurfaceHolder; @@ -34,7 +35,6 @@ import java.lang.ref.WeakReference; import java.util.ArrayList; import java.util.HashMap; import java.util.List; -import java.util.StringTokenizer; import java.util.concurrent.locks.ReentrantLock; /** @@ -1905,7 +1905,7 @@ public class Camera { private HashMap<String, String> mMap; private Parameters() { - mMap = new HashMap<String, String>(); + mMap = new HashMap<String, String>(64); } /** @@ -1929,7 +1929,7 @@ public class Camera { * semi-colon delimited key-value pairs */ public String flatten() { - StringBuilder flattened = new StringBuilder(); + StringBuilder flattened = new StringBuilder(128); for (String k : mMap.keySet()) { flattened.append(k); flattened.append("="); @@ -1952,9 +1952,9 @@ public class Camera { public void unflatten(String flattened) { mMap.clear(); - StringTokenizer tokenizer = new StringTokenizer(flattened, ";"); - while (tokenizer.hasMoreElements()) { - String kv = tokenizer.nextToken(); + TextUtils.StringSplitter splitter = new TextUtils.SimpleStringSplitter(';'); + splitter.setString(flattened); + for (String kv : splitter) { int pos = kv.indexOf('='); if (pos == -1) { continue; @@ -3488,11 +3488,11 @@ public class Camera { private ArrayList<String> split(String str) { if (str == null) return null; - // Use StringTokenizer because it is faster than split. - StringTokenizer tokenizer = new StringTokenizer(str, ","); + TextUtils.StringSplitter splitter = new TextUtils.SimpleStringSplitter(','); + splitter.setString(str); ArrayList<String> substrings = new ArrayList<String>(); - while (tokenizer.hasMoreElements()) { - substrings.add(tokenizer.nextToken()); + for (String s : splitter) { + substrings.add(s); } return substrings; } @@ -3502,11 +3502,11 @@ public class Camera { private ArrayList<Integer> splitInt(String str) { if (str == null) return null; - StringTokenizer tokenizer = new StringTokenizer(str, ","); + TextUtils.StringSplitter splitter = new TextUtils.SimpleStringSplitter(','); + splitter.setString(str); ArrayList<Integer> substrings = new ArrayList<Integer>(); - while (tokenizer.hasMoreElements()) { - String token = tokenizer.nextToken(); - substrings.add(Integer.parseInt(token)); + for (String s : splitter) { + substrings.add(Integer.parseInt(s)); } if (substrings.size() == 0) return null; return substrings; @@ -3515,11 +3515,11 @@ public class Camera { private void splitInt(String str, int[] output) { if (str == null) return; - StringTokenizer tokenizer = new StringTokenizer(str, ","); + TextUtils.StringSplitter splitter = new TextUtils.SimpleStringSplitter(','); + splitter.setString(str); int index = 0; - while (tokenizer.hasMoreElements()) { - String token = tokenizer.nextToken(); - output[index++] = Integer.parseInt(token); + for (String s : splitter) { + output[index++] = Integer.parseInt(s); } } @@ -3527,11 +3527,11 @@ public class Camera { private void splitFloat(String str, float[] output) { if (str == null) return; - StringTokenizer tokenizer = new StringTokenizer(str, ","); + TextUtils.StringSplitter splitter = new TextUtils.SimpleStringSplitter(','); + splitter.setString(str); int index = 0; - while (tokenizer.hasMoreElements()) { - String token = tokenizer.nextToken(); - output[index++] = Float.parseFloat(token); + for (String s : splitter) { + output[index++] = Float.parseFloat(s); } } @@ -3558,10 +3558,11 @@ public class Camera { private ArrayList<Size> splitSize(String str) { if (str == null) return null; - StringTokenizer tokenizer = new StringTokenizer(str, ","); + TextUtils.StringSplitter splitter = new TextUtils.SimpleStringSplitter(','); + splitter.setString(str); ArrayList<Size> sizeList = new ArrayList<Size>(); - while (tokenizer.hasMoreElements()) { - Size size = strToSize(tokenizer.nextToken()); + for (String s : splitter) { + Size size = strToSize(s); if (size != null) sizeList.add(size); } if (sizeList.size() == 0) return null; |