Cleanup the resources parsing a bit
Bug: 203938029
Test: manual
Change-Id: Ib4d87bc7ee3fbea9be65302ad8ca7a8759b20d62
diff --git a/libs/androidfw/LoadedArsc.cpp b/libs/androidfw/LoadedArsc.cpp
index 8150e78..bbd4c81 100644
--- a/libs/androidfw/LoadedArsc.cpp
+++ b/libs/androidfw/LoadedArsc.cpp
@@ -641,22 +641,25 @@
}
// Retrieve all the resource ids belonging to this policy chunk
- std::unordered_set<uint32_t> ids;
const auto ids_begin = overlayable_child_chunk.data_ptr().convert<ResTable_ref>();
const auto ids_end = ids_begin + dtohl(policy_header->entry_count);
+ std::unordered_set<uint32_t> ids;
+ ids.reserve(ids_end - ids_begin);
for (auto id_iter = ids_begin; id_iter != ids_end; ++id_iter) {
if (!id_iter) {
+ LOG(ERROR) << "NULL ResTable_ref record??";
return {};
}
ids.insert(dtohl(id_iter->ident));
}
// Add the pairing of overlayable properties and resource ids to the package
- OverlayableInfo overlayable_info{};
- overlayable_info.name = name;
- overlayable_info.actor = actor;
- overlayable_info.policy_flags = policy_header->policy_flags;
- loaded_package->overlayable_infos_.emplace_back(overlayable_info, ids);
+ OverlayableInfo overlayable_info {
+ .name = name,
+ .actor = actor,
+ .policy_flags = policy_header->policy_flags
+ };
+ loaded_package->overlayable_infos_.emplace_back(std::move(overlayable_info), std::move(ids));
loaded_package->defines_overlayable_ = true;
break;
}
@@ -683,7 +686,6 @@
break;
}
- std::unordered_set<uint32_t> finalized_ids;
const auto lib_alias = child_chunk.header<ResTable_staged_alias_header>();
if (!lib_alias) {
LOG(ERROR) << "RES_TABLE_STAGED_ALIAS_TYPE is too small.";
@@ -696,8 +698,11 @@
}
const auto entry_begin = child_chunk.data_ptr().convert<ResTable_staged_alias_entry>();
const auto entry_end = entry_begin + dtohl(lib_alias->count);
+ std::unordered_set<uint32_t> finalized_ids;
+ finalized_ids.reserve(entry_end - entry_begin);
for (auto entry_iter = entry_begin; entry_iter != entry_end; ++entry_iter) {
if (!entry_iter) {
+ LOG(ERROR) << "NULL ResTable_staged_alias_entry record??";
return {};
}
auto finalized_id = dtohl(entry_iter->finalizedResId);
@@ -708,8 +713,7 @@
}
auto staged_id = dtohl(entry_iter->stagedResId);
- auto [_, success] = loaded_package->alias_id_map_.insert(std::make_pair(staged_id,
- finalized_id));
+ auto [_, success] = loaded_package->alias_id_map_.emplace(staged_id, finalized_id);
if (!success) {
LOG(ERROR) << StringPrintf("Repeated staged resource id '%08x' in staged aliases.",
staged_id);