summaryrefslogtreecommitdiff
path: root/libs/androidfw/AssetManager2.cpp
diff options
context:
space:
mode:
author Yurii Zubrytskyi <zyy@google.com> 2023-03-29 12:53:51 -0700
committer Yurii Zubrytskyi <zyy@google.com> 2023-04-13 02:44:17 -0700
commitff9cba7ec796a06923d3daaa3104624a7dadc61e (patch)
treebe0932ce7329bf91d871b50b72ccae4194efb2c7 /libs/androidfw/AssetManager2.cpp
parent831fda61c30077b5acc6b4df46302120e5a8f84f (diff)
[nit] Clean up the resource resolution debugging
- Better struct memory layout - Get rid of unneeded unordered_map Bug: n/a Test: builds Change-Id: I3c7d8d99bff5aa35621b61956a0fd2f5a7a48aa3
Diffstat (limited to 'libs/androidfw/AssetManager2.cpp')
-rw-r--r--libs/androidfw/AssetManager2.cpp45
1 files changed, 18 insertions, 27 deletions
diff --git a/libs/androidfw/AssetManager2.cpp b/libs/androidfw/AssetManager2.cpp
index 68f5e4a88c7e..bc46cf5a98ce 100644
--- a/libs/androidfw/AssetManager2.cpp
+++ b/libs/androidfw/AssetManager2.cpp
@@ -632,7 +632,7 @@ base::expected<FindEntryResult, NullOrIOError> AssetManager2::FindEntry(
if (UNLIKELY(logging_enabled)) {
last_resolution_.steps.push_back(
- Resolution::Step{Resolution::Step::Type::OVERLAID_INLINE, String8(), result->cookie});
+ Resolution::Step{Resolution::Step::Type::OVERLAID_INLINE, result->cookie, String8()});
if (auto path = apk_assets_[result->cookie]->GetPath()) {
const std::string overlay_path = path->data();
if (IsFabricatedOverlay(overlay_path)) {
@@ -682,8 +682,8 @@ base::expected<FindEntryResult, NullOrIOError> AssetManager2::FindEntry(
if (UNLIKELY(logging_enabled)) {
last_resolution_.steps.push_back(
- Resolution::Step{Resolution::Step::Type::OVERLAID, overlay_result->config.toString(),
- overlay_result->cookie});
+ Resolution::Step{Resolution::Step::Type::OVERLAID, overlay_result->cookie,
+ overlay_result->config.toString()});
last_resolution_.best_package_name =
overlay_result->package_name->c_str();
overlaid = true;
@@ -769,8 +769,7 @@ base::expected<FindEntryResult, NullOrIOError> AssetManager2::FindEntryInternal(
} else {
if (UNLIKELY(logging_enabled)) {
last_resolution_.steps.push_back(Resolution::Step{Resolution::Step::Type::SKIPPED,
- this_config.toString(),
- cookie});
+ cookie, this_config.toString()});
}
continue;
}
@@ -786,8 +785,7 @@ base::expected<FindEntryResult, NullOrIOError> AssetManager2::FindEntryInternal(
if (!offset.has_value()) {
if (UNLIKELY(logging_enabled)) {
last_resolution_.steps.push_back(Resolution::Step{Resolution::Step::Type::NO_ENTRY,
- this_config.toString(),
- cookie});
+ cookie, this_config.toString()});
}
continue;
}
@@ -800,8 +798,7 @@ base::expected<FindEntryResult, NullOrIOError> AssetManager2::FindEntryInternal(
if (UNLIKELY(logging_enabled)) {
last_resolution_.steps.push_back(Resolution::Step{resolution_type,
- this_config.toString(),
- cookie});
+ cookie, this_config.toString()});
}
// Any configuration will suffice, so break.
@@ -839,13 +836,7 @@ base::expected<FindEntryResult, NullOrIOError> AssetManager2::FindEntryInternal(
}
void AssetManager2::ResetResourceResolution() const {
- last_resolution_.cookie = kInvalidCookie;
- last_resolution_.resid = 0;
- last_resolution_.steps.clear();
- last_resolution_.type_string_ref = StringPoolRef();
- last_resolution_.entry_string_ref = StringPoolRef();
- last_resolution_.best_config_name.clear();
- last_resolution_.best_package_name.clear();
+ last_resolution_ = Resolution{};
}
void AssetManager2::SetResourceResolutionLoggingEnabled(bool enabled) {
@@ -885,21 +876,21 @@ std::string AssetManager2::GetLastResourceResolution() const {
configuration_.toString().c_str());
for (const Resolution::Step& step : last_resolution_.steps) {
- const static std::unordered_map<Resolution::Step::Type, const char*> kStepStrings = {
- {Resolution::Step::Type::INITIAL, "Found initial"},
- {Resolution::Step::Type::BETTER_MATCH, "Found better"},
- {Resolution::Step::Type::OVERLAID, "Overlaid"},
- {Resolution::Step::Type::OVERLAID_INLINE, "Overlaid inline"},
- {Resolution::Step::Type::SKIPPED, "Skipped"},
- {Resolution::Step::Type::NO_ENTRY, "No entry"}
+ constexpr static std::array kStepStrings = {
+ "Found initial",
+ "Found better",
+ "Overlaid",
+ "Overlaid inline",
+ "Skipped",
+ "No entry"
};
- const auto prefix = kStepStrings.find(step.type);
- if (prefix == kStepStrings.end()) {
+ if (step.type < Resolution::Step::Type::INITIAL
+ || step.type > Resolution::Step::Type::NO_ENTRY) {
continue;
}
-
- log_stream << "\n\t" << prefix->second << ": " << apk_assets_[step.cookie]->GetDebugName();
+ const auto prefix = kStepStrings[int(step.type) - int(Resolution::Step::Type::INITIAL)];
+ log_stream << "\n\t" << prefix << ": " << apk_assets_[step.cookie]->GetDebugName();
if (!step.config_name.isEmpty()) {
log_stream << " - " << step.config_name;
}