Optimize IntentResolver to reduce lookup time by 50%.
IntentResolver frequently iterates over hundreds of different IntentFilters
and spends much of its time creating iterators and comparing strings.
This change avoids reduces the amount of garbage created by eschewing
iterators where possible. The FastImmutableArraySet type on its own
provides a 2.5x speed boost compared to repeatedly iterating over a HashSet.
In absolute terms, during orientation changes we spent about 160ms resolving
11 intents and performing 1129 calls to IntentFilter.match. Now we spend
half of that time.
Change-Id: Ia120e0082c8cf0b572a0317b9ef4a22c766dbad6
diff --git a/core/java/android/content/Intent.java b/core/java/android/content/Intent.java
index 6e3663e..e7b96e7 100644
--- a/core/java/android/content/Intent.java
+++ b/core/java/android/content/Intent.java
@@ -2794,7 +2794,7 @@
* @param action The Intent action, such as ACTION_VIEW.
*/
public Intent(String action) {
- mAction = action;
+ setAction(action);
}
/**
@@ -2814,7 +2814,7 @@
* @param uri The Intent data URI.
*/
public Intent(String action, Uri uri) {
- mAction = action;
+ setAction(action);
mData = uri;
}
@@ -2863,7 +2863,7 @@
*/
public Intent(String action, Uri uri,
Context packageContext, Class<?> cls) {
- mAction = action;
+ setAction(action);
mData = uri;
mComponent = new ComponentName(packageContext, cls);
}
@@ -2985,7 +2985,7 @@
// action
if (uri.startsWith("action=", i)) {
- intent.mAction = value;
+ intent.setAction(value);
}
// categories
@@ -4061,7 +4061,7 @@
* @see #getAction
*/
public Intent setAction(String action) {
- mAction = action;
+ mAction = action != null ? action.intern() : null;
return this;
}
@@ -4165,7 +4165,7 @@
if (mCategories == null) {
mCategories = new HashSet<String>();
}
- mCategories.add(category);
+ mCategories.add(category.intern());
return this;
}
@@ -5678,7 +5678,7 @@
}
public void readFromParcel(Parcel in) {
- mAction = in.readString();
+ setAction(in.readString());
mData = Uri.CREATOR.createFromParcel(in);
mType = in.readString();
mFlags = in.readInt();
@@ -5694,7 +5694,7 @@
mCategories = new HashSet<String>();
int i;
for (i=0; i<N; i++) {
- mCategories.add(in.readString());
+ mCategories.add(in.readString().intern());
}
} else {
mCategories = null;