Preventing multiple calls to loadLabel for the same info within a single load.

- Fixing mind boggling bug where we weren't even using the label cache earlier.

Change-Id: I605abf4d589ad02b2426d20adfe9cd1773cc84fd
This commit is contained in:
Winson Chung
2011-07-11 17:44:15 -07:00
parent 3818eaf848
commit c3eecff904
5 changed files with 75 additions and 42 deletions

View File

@@ -125,9 +125,10 @@ public class IconCache {
/**
* Fill in "application" with the icon and label for "info."
*/
public void getTitleAndIcon(ApplicationInfo application, ResolveInfo info) {
public void getTitleAndIcon(ApplicationInfo application, ResolveInfo info,
HashMap<Object, CharSequence> labelCache) {
synchronized (mCache) {
CacheEntry entry = cacheLocked(application.componentName, info);
CacheEntry entry = cacheLocked(application.componentName, info, labelCache);
application.title = entry.title;
application.iconBitmap = entry.icon;
@@ -143,7 +144,7 @@ public class IconCache {
return mDefaultIcon;
}
CacheEntry entry = cacheLocked(component, resolveInfo);
CacheEntry entry = cacheLocked(component, resolveInfo, null);
return entry.icon;
}
}
@@ -154,7 +155,7 @@ public class IconCache {
return null;
}
CacheEntry entry = cacheLocked(component, resolveInfo);
CacheEntry entry = cacheLocked(component, resolveInfo, null);
return entry.icon;
}
}
@@ -163,14 +164,22 @@ public class IconCache {
return mDefaultIcon == icon;
}
private CacheEntry cacheLocked(ComponentName componentName, ResolveInfo info) {
private CacheEntry cacheLocked(ComponentName componentName, ResolveInfo info,
HashMap<Object, CharSequence> labelCache) {
CacheEntry entry = mCache.get(componentName);
if (entry == null) {
entry = new CacheEntry();
mCache.put(componentName, entry);
entry.title = info.loadLabel(mPackageManager).toString();
if (labelCache != null && labelCache.containsKey(info)) {
entry.title = labelCache.get(info).toString();
} else {
entry.title = info.loadLabel(mPackageManager).toString();
if (labelCache != null) {
labelCache.put(info, entry.title);
}
}
if (entry.title == null) {
entry.title = info.activityInfo.name;
}