Merge "Performance improvements in AssetManager" into nyc-dev am: 3765d34d36
am: 2b798a2344
* commit '2b798a2344feeeb64b74e8dab4042f7d7f3879ab':
Performance improvements in AssetManager
Change-Id: I01c50ad7695e478f299f497441fdea0ab8e24116
This commit is contained in:
@@ -1924,6 +1924,10 @@ private:
|
|||||||
|
|
||||||
void print_value(const Package* pkg, const Res_value& value) const;
|
void print_value(const Package* pkg, const Res_value& value) const;
|
||||||
|
|
||||||
|
template <typename Func>
|
||||||
|
void forEachConfiguration(bool ignoreMipmap, bool ignoreAndroidPackage,
|
||||||
|
bool includeSystemConfigs, const Func& f) const;
|
||||||
|
|
||||||
mutable Mutex mLock;
|
mutable Mutex mLock;
|
||||||
|
|
||||||
// Mutex that controls access to the list of pre-filtered configurations
|
// Mutex that controls access to the list of pre-filtered configurations
|
||||||
|
|||||||
@@ -66,7 +66,6 @@ static const char* kAssetsRoot = "assets";
|
|||||||
static const char* kAppZipName = NULL; //"classes.jar";
|
static const char* kAppZipName = NULL; //"classes.jar";
|
||||||
static const char* kSystemAssets = "framework/framework-res.apk";
|
static const char* kSystemAssets = "framework/framework-res.apk";
|
||||||
static const char* kResourceCache = "resource-cache";
|
static const char* kResourceCache = "resource-cache";
|
||||||
static const char* kAndroidManifest = "AndroidManifest.xml";
|
|
||||||
|
|
||||||
static const char* kExcludeExtension = ".EXCLUDE";
|
static const char* kExcludeExtension = ".EXCLUDE";
|
||||||
|
|
||||||
@@ -203,16 +202,6 @@ bool AssetManager::addAssetPath(
|
|||||||
ALOGV("In %p Asset %s path: %s", this,
|
ALOGV("In %p Asset %s path: %s", this,
|
||||||
ap.type == kFileTypeDirectory ? "dir" : "zip", ap.path.string());
|
ap.type == kFileTypeDirectory ? "dir" : "zip", ap.path.string());
|
||||||
|
|
||||||
// Check that the path has an AndroidManifest.xml
|
|
||||||
Asset* manifestAsset = const_cast<AssetManager*>(this)->openNonAssetInPathLocked(
|
|
||||||
kAndroidManifest, Asset::ACCESS_BUFFER, ap);
|
|
||||||
if (manifestAsset == NULL) {
|
|
||||||
// This asset path does not contain any resources.
|
|
||||||
delete manifestAsset;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
delete manifestAsset;
|
|
||||||
|
|
||||||
ap.isSystemAsset = isSystemAsset;
|
ap.isSystemAsset = isSystemAsset;
|
||||||
mAssetPaths.add(ap);
|
mAssetPaths.add(ap);
|
||||||
|
|
||||||
|
|||||||
@@ -5822,10 +5822,11 @@ static bool compareResTableConfig(const ResTable_config& a, const ResTable_confi
|
|||||||
return a.compare(b) < 0;
|
return a.compare(b) < 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ResTable::getConfigurations(Vector<ResTable_config>* configs, bool ignoreMipmap,
|
template <typename Func>
|
||||||
bool ignoreAndroidPackage, bool includeSystemConfigs) const {
|
void ResTable::forEachConfiguration(bool ignoreMipmap, bool ignoreAndroidPackage,
|
||||||
|
bool includeSystemConfigs, const Func& f) const {
|
||||||
const size_t packageCount = mPackageGroups.size();
|
const size_t packageCount = mPackageGroups.size();
|
||||||
String16 android("android");
|
const String16 android("android");
|
||||||
for (size_t i = 0; i < packageCount; i++) {
|
for (size_t i = 0; i < packageCount; i++) {
|
||||||
const PackageGroup* packageGroup = mPackageGroups[i];
|
const PackageGroup* packageGroup = mPackageGroups[i];
|
||||||
if (ignoreAndroidPackage && android == packageGroup->name) {
|
if (ignoreAndroidPackage && android == packageGroup->name) {
|
||||||
@@ -5853,42 +5854,47 @@ void ResTable::getConfigurations(Vector<ResTable_config>* configs, bool ignoreMi
|
|||||||
memset(&cfg, 0, sizeof(ResTable_config));
|
memset(&cfg, 0, sizeof(ResTable_config));
|
||||||
cfg.copyFromDtoH(config->config);
|
cfg.copyFromDtoH(config->config);
|
||||||
|
|
||||||
auto iter = std::lower_bound(configs->begin(), configs->end(), cfg,
|
f(cfg);
|
||||||
compareResTableConfig);
|
|
||||||
if (iter == configs->end() || iter->compare(cfg) != 0) {
|
|
||||||
configs->insertAt(cfg, std::distance(configs->begin(), iter));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ResTable::getConfigurations(Vector<ResTable_config>* configs, bool ignoreMipmap,
|
||||||
|
bool ignoreAndroidPackage, bool includeSystemConfigs) const {
|
||||||
|
auto func = [&](const ResTable_config& cfg) {
|
||||||
|
const auto beginIter = configs->begin();
|
||||||
|
const auto endIter = configs->end();
|
||||||
|
|
||||||
|
auto iter = std::lower_bound(beginIter, endIter, cfg, compareResTableConfig);
|
||||||
|
if (iter == endIter || iter->compare(cfg) != 0) {
|
||||||
|
configs->insertAt(cfg, std::distance(beginIter, iter));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
forEachConfiguration(ignoreMipmap, ignoreAndroidPackage, includeSystemConfigs, func);
|
||||||
|
}
|
||||||
|
|
||||||
static bool compareString8AndCString(const String8& str, const char* cStr) {
|
static bool compareString8AndCString(const String8& str, const char* cStr) {
|
||||||
return strcmp(str.string(), cStr) < 0;
|
return strcmp(str.string(), cStr) < 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ResTable::getLocales(Vector<String8>* locales, bool includeSystemLocales) const
|
void ResTable::getLocales(Vector<String8>* locales, bool includeSystemLocales) const {
|
||||||
{
|
|
||||||
Vector<ResTable_config> configs;
|
|
||||||
ALOGV("calling getConfigurations");
|
|
||||||
getConfigurations(&configs,
|
|
||||||
false /* ignoreMipmap */,
|
|
||||||
false /* ignoreAndroidPackage */,
|
|
||||||
includeSystemLocales /* includeSystemConfigs */);
|
|
||||||
ALOGV("called getConfigurations size=%d", (int)configs.size());
|
|
||||||
const size_t I = configs.size();
|
|
||||||
|
|
||||||
char locale[RESTABLE_MAX_LOCALE_LEN];
|
char locale[RESTABLE_MAX_LOCALE_LEN];
|
||||||
for (size_t i=0; i<I; i++) {
|
|
||||||
configs[i].getBcp47Locale(locale);
|
|
||||||
|
|
||||||
auto iter = std::lower_bound(locales->begin(), locales->end(), locale,
|
forEachConfiguration(false, false, includeSystemLocales, [&](const ResTable_config& cfg) {
|
||||||
compareString8AndCString);
|
if (cfg.locale != 0) {
|
||||||
if (iter == locales->end() || strcmp(iter->string(), locale) != 0) {
|
cfg.getBcp47Locale(locale);
|
||||||
locales->insertAt(String8(locale), std::distance(locales->begin(), iter));
|
|
||||||
|
const auto beginIter = locales->begin();
|
||||||
|
const auto endIter = locales->end();
|
||||||
|
|
||||||
|
auto iter = std::lower_bound(beginIter, endIter, locale, compareString8AndCString);
|
||||||
|
if (iter == endIter || strcmp(iter->string(), locale) != 0) {
|
||||||
|
locales->insertAt(String8(locale), std::distance(beginIter, iter));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
StringPoolRef::StringPoolRef(const ResStringPool* pool, uint32_t index)
|
StringPoolRef::StringPoolRef(const ResStringPool* pool, uint32_t index)
|
||||||
|
|||||||
Reference in New Issue
Block a user