Bug 962968 - Replace HashMap with SparseArray in PrefsHelper (r=rnewman)

This commit is contained in:
Lucas Rocha 2014-01-23 19:00:06 +00:00
parent 289752a05d
commit 37d75c52d3

View File

@ -12,10 +12,9 @@ import org.json.JSONException;
import org.json.JSONObject;
import android.util.Log;
import android.util.SparseArray;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
/**
* Helper class to get/set gecko prefs.
@ -24,7 +23,7 @@ public final class PrefsHelper {
private static final String LOGTAG = "GeckoPrefsHelper";
private static boolean sRegistered = false;
private static final Map<Integer, PrefHandler> sCallbacks = new HashMap<Integer, PrefHandler>();
private static final SparseArray<PrefHandler> sCallbacks = new SparseArray<PrefHandler>();
private static int sUniqueRequestId = 1;
public static int getPref(String prefName, PrefHandler callback) {
@ -73,7 +72,7 @@ public final class PrefsHelper {
int requestId = message.getInt("requestId");
callback = sCallbacks.get(requestId);
if (callback != null && !callback.isObserver()) {
sCallbacks.remove(requestId);
sCallbacks.delete(requestId);
}
} catch (Exception e) {
callback = null;
@ -144,7 +143,9 @@ public final class PrefsHelper {
}
synchronized (PrefsHelper.class) {
PrefHandler callback = sCallbacks.remove(requestId);
PrefHandler callback = sCallbacks.get(requestId);
sCallbacks.delete(requestId);
if (callback == null) {
Log.e(LOGTAG, "Unknown request ID " + requestId);
return;