From d21d444426911d93c507a929a8223ebf63258954 Mon Sep 17 00:00:00 2001 From: Kenny Root Date: Fri, 22 Jul 2011 15:32:30 -0700 Subject: 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 --- core/java/android/content/pm/Signature.java | 25 ++++++++++++++++--------- 1 file 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= '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; } -- cgit v1.1