Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit de0ff637 authored by Kenny Root's avatar Kenny Root
Browse files

Reduce footprint of Signature from ~7000 to ~1448

Signature had lazy initialization of the mString member when needed, but
it would stick around forever when initialized. Each package had one or
more Signatures that would be ~7000 bytes each. At a couple hundred
packages, that's over 1.3MB just for signatures.

Whenever packages.xml was written out, it would write the Signature for
each program as well which happens at boot thereby initializing the
mString member pretty much immediately.

Change-Id: Idb882ffeca2861b3e87437fc83f001710d6c0441
parent d85621c9
Loading
Loading
Loading
Loading
+9 −5
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import android.content.ComponentName;
import android.os.Parcel;
import android.os.Parcelable;

import java.lang.ref.SoftReference;
import java.util.Arrays;

/**
@@ -30,7 +31,7 @@ public class Signature implements Parcelable {
    private final byte[] mSignature;
    private int mHashCode;
    private boolean mHaveHashCode;
    private String mString;
    private SoftReference<String> mStringRef;

    /**
     * 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.
     */
    public String toCharsString() {
        if (mString != null) return mString;
        String str = new String(toChars());
        mString = str;
        return mString;
        String str = mStringRef == null ? null : mStringRef.get();
        if (str != null) {
            return str;
        }
        str = new String(toChars());
        mStringRef = new SoftReference<String>(str);
        return str;
    }

    /**