From e7c1f00739c0f2747acb353ccef2b41f2a92a01e Mon Sep 17 00:00:00 2001 From: Yurii Zubrytskyi Date: Tue, 30 Jan 2024 13:50:57 -0800 Subject: [res] Use fstat() for idmap::IsUpToDate() The most common operation when getting a new Resources object is checking if all apks and overlays are still up to date to reuse the cached object. It makes sense to optimize it by excluding the file by path lookups and instead keeping an open FD to the file in the cache + Make IsFabricatedOverlay() more efficient via a name check and string_view where possible Bug: 282215580 Test: build + boot + presubmit Change-Id: Ib1ab20cba359c2195a72dd2e10096883d95b4453 --- libs/androidfw/ApkAssets.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'libs/androidfw/ApkAssets.cpp') diff --git a/libs/androidfw/ApkAssets.cpp b/libs/androidfw/ApkAssets.cpp index f0c639574a9f..49254d1c6f6e 100644 --- a/libs/androidfw/ApkAssets.cpp +++ b/libs/androidfw/ApkAssets.cpp @@ -81,7 +81,7 @@ ApkAssetsPtr ApkAssets::LoadOverlay(const std::string& idmap_path, package_prope std::string overlay_path(loaded_idmap->OverlayApkPath()); auto fd = unique_fd(base::utf8::open(overlay_path.c_str(), O_RDONLY | O_CLOEXEC)); std::unique_ptr overlay_assets; - if (IsFabricatedOverlay(fd)) { + if (IsFabricatedOverlayName(overlay_path) && IsFabricatedOverlay(fd)) { // Fabricated overlays do not contain resource definitions. All of the overlay resource values // are defined inline in the idmap. overlay_assets = EmptyAssetsProvider::Create(std::move(overlay_path)); @@ -137,8 +137,7 @@ ApkAssetsPtr ApkAssets::LoadImpl(std::unique_ptr resources_asset, return {}; } loaded_arsc = LoadedArsc::Load(data, length, loaded_idmap.get(), property_flags); - } else if (loaded_idmap != nullptr && - IsFabricatedOverlay(std::string(loaded_idmap->OverlayApkPath()))) { + } else if (loaded_idmap != nullptr && IsFabricatedOverlay(loaded_idmap->OverlayApkPath())) { loaded_arsc = LoadedArsc::Load(loaded_idmap.get()); } else { loaded_arsc = LoadedArsc::CreateEmpty(); -- cgit v1.2.3-59-g8ed1b