Merge "Reduce footprint of Signature from ~7000 to ~1448" into gingerbread

This commit is contained in:
Kenny Root
2010-09-03 16:59:42 -07:00
committed by Android (Google) Code Review

View File

@@ -20,6 +20,7 @@ import android.content.ComponentName;
import android.os.Parcel; import android.os.Parcel;
import android.os.Parcelable; import android.os.Parcelable;
import java.lang.ref.SoftReference;
import java.util.Arrays; import java.util.Arrays;
/** /**
@@ -30,7 +31,7 @@ public class Signature implements Parcelable {
private final byte[] mSignature; private final byte[] mSignature;
private int mHashCode; private int mHashCode;
private boolean mHaveHashCode; private boolean mHaveHashCode;
private String mString; private SoftReference<String> mStringRef;
/** /**
* Create Signature from an existing raw byte array. * Create Signature from an existing raw byte array.
@@ -96,10 +97,13 @@ public class Signature implements Parcelable {
* cached so future calls will return the same String. * cached so future calls will return the same String.
*/ */
public String toCharsString() { public String toCharsString() {
if (mString != null) return mString; String str = mStringRef == null ? null : mStringRef.get();
String str = new String(toChars()); if (str != null) {
mString = str; return str;
return mString; }
str = new String(toChars());
mStringRef = new SoftReference<String>(str);
return str;
} }
/** /**