You've already forked android_translation_layer
mirror of
https://gitlab.com/android_translation_layer/android_translation_layer.git
synced 2025-10-27 11:48:10 -07:00
AssetManager: speed up XML inflation using HashMap caching
This makes XML inflation around 10 times faster. Inflating a layout XML with one TextView and one ImageView now takes 4 ms instead of 40 ms
This commit is contained in:
@@ -147,13 +147,18 @@ public final class AssetManager {
|
||||
}
|
||||
}
|
||||
|
||||
private Map<Integer, EntryGroup> tableBlockCache = new HashMap<>();
|
||||
private EntryGroup tableBlockSearch(int resId) {
|
||||
if (tableBlockCache.containsKey(resId)) {
|
||||
return tableBlockCache.get(resId);
|
||||
}
|
||||
EntryGroup ret = null;
|
||||
for (TableBlock tableBlock : tableBlocks) {
|
||||
ret = tableBlock.search(resId);
|
||||
if (ret != null)
|
||||
break;
|
||||
}
|
||||
tableBlockCache.put(resId, ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -913,6 +918,12 @@ public final class AssetManager {
|
||||
ResXmlPullParser parser = (ResXmlPullParser)set;
|
||||
outIndices[0] = 0;
|
||||
|
||||
Map<Integer,Integer> xmlCache = new HashMap<>();
|
||||
if (set != null) {
|
||||
for (int j=0; j<set.getAttributeCount(); j++) {
|
||||
xmlCache.put(set.getAttributeNameResource(j), j);
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < inAttrs.length; i++) {
|
||||
int d = i*AssetManager.STYLE_NUM_ENTRIES;
|
||||
// reset values in case of cached array
|
||||
@@ -928,13 +939,8 @@ public final class AssetManager {
|
||||
ValueItem valueItem = null;
|
||||
while ("attr".equals(entry.getTypeName())) {
|
||||
valueItem = null;
|
||||
if (set != null) {
|
||||
for (int j=0; j<set.getAttributeCount(); j++) {
|
||||
if (set.getAttributeNameResource(j) == resId) {
|
||||
valueItem = parser.getResXmlAttributeAt(j);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (xmlCache.containsKey(resId)) {
|
||||
valueItem = parser.getResXmlAttributeAt(xmlCache.get(resId));
|
||||
}
|
||||
if (valueItem == null) {
|
||||
valueItem = defStyle.get(resId);
|
||||
|
||||
Reference in New Issue
Block a user