summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKenny Root <kroot@google.com>2011-07-22 15:32:30 -0700
committerKenny Root <kroot@google.com>2011-07-22 15:32:30 -0700
commitd21d444426911d93c507a929a8223ebf63258954 (patch)
tree354df4200addb7383086aaa14ead3e2dc2107d56
parent460418eb35b49baf5edd4e23534bb5121efc7d64 (diff)
downloadframeworks_base-d21d444426911d93c507a929a8223ebf63258954.zip
frameworks_base-d21d444426911d93c507a929a8223ebf63258954.tar.gz
frameworks_base-d21d444426911d93c507a929a8223ebf63258954.tar.bz2
Stop using charAt for Signatures
Simply getting the byte array and operating on that instead of using String.charAt() repeatedly speeds up Signature initializer calls during bootup from 150ms to 9ms (1700% faster). Change-Id: I85ef17ef63477927e0181d5f49a1d521b7b0d98b
-rw-r--r--core/java/android/content/pm/Signature.java25
1 files changed, 16 insertions, 9 deletions
diff --git a/core/java/android/content/pm/Signature.java b/core/java/android/content/pm/Signature.java
index d4e5cc1..b32664e 100644
--- a/core/java/android/content/pm/Signature.java
+++ b/core/java/android/content/pm/Signature.java
@@ -45,16 +45,23 @@ public class Signature implements Parcelable {
* {@link #toChars} or {@link #toCharsString()}.
*/
public Signature(String text) {
- final int N = text.length()/2;
- byte[] sig = new byte[N];
- for (int i=0; i<N; i++) {
- char c = text.charAt(i*2);
- byte b = (byte)(
- (c >= 'a' ? (c - 'a' + 10) : (c - '0'))<<4);
- c = text.charAt(i*2 + 1);
- b |= (byte)(c >= 'a' ? (c - 'a' + 10) : (c - '0'));
- sig[i] = b;
+ final byte[] input = text.getBytes();
+ final int N = input.length;
+ final byte[] sig = new byte[N / 2];
+ int sigIndex = 0;
+
+ for (int i = 0; i < N;) {
+ int b;
+
+ final int hi = input[i++];
+ b = (hi >= 'a' ? (hi - 'a' + 10) : (hi - '0')) << 4;
+
+ final int lo = input[i++];
+ b |= (lo >= 'a' ? (lo - 'a' + 10) : (lo - '0')) & 0x0F;
+
+ sig[sigIndex++] = (byte) (b & 0xFF);
}
+
mSignature = sig;
}