summaryrefslogtreecommitdiff
path: root/libs/androidfw/Idmap.cpp
diff options
context:
space:
mode:
author Yurii Zubrytskyi <zyy@google.com> 2024-01-30 13:50:57 -0800
committer Yurii Zubrytskyi <zyy@google.com> 2024-02-29 17:43:06 +0000
commite7c1f00739c0f2747acb353ccef2b41f2a92a01e (patch)
tree2f75c7f3cdd227fa0ff41ba1731cf31f99771018 /libs/androidfw/Idmap.cpp
parent43ff4a403fb4abad851d387a341e1184c015463e (diff)
[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
Diffstat (limited to 'libs/androidfw/Idmap.cpp')
-rw-r--r--libs/androidfw/Idmap.cpp15
1 files changed, 11 insertions, 4 deletions
diff --git a/libs/androidfw/Idmap.cpp b/libs/androidfw/Idmap.cpp
index 5f98b8f8db43..982419059ead 100644
--- a/libs/androidfw/Idmap.cpp
+++ b/libs/androidfw/Idmap.cpp
@@ -18,8 +18,10 @@
#include "androidfw/Idmap.h"
+#include "android-base/file.h"
#include "android-base/logging.h"
#include "android-base/stringprintf.h"
+#include "android-base/utf8.h"
#include "androidfw/misc.h"
#include "androidfw/ResourceTypes.h"
#include "androidfw/Util.h"
@@ -250,7 +252,12 @@ std::optional<std::string_view> ReadString(const uint8_t** in_out_data_ptr, size
}
} // namespace
-LoadedIdmap::LoadedIdmap(std::string&& idmap_path, const Idmap_header* header,
+// O_PATH is a lightweight way of creating an FD, only exists on Linux
+#ifndef O_PATH
+#define O_PATH (0)
+#endif
+
+LoadedIdmap::LoadedIdmap(const std::string& idmap_path, const Idmap_header* header,
const Idmap_data_header* data_header,
const Idmap_target_entry* target_entries,
const Idmap_target_entry_inline* target_inline_entries,
@@ -267,10 +274,10 @@ LoadedIdmap::LoadedIdmap(std::string&& idmap_path, const Idmap_header* header,
configurations_(configs),
overlay_entries_(overlay_entries),
string_pool_(std::move(string_pool)),
- idmap_path_(std::move(idmap_path)),
+ idmap_fd_(android::base::utf8::open(idmap_path.c_str(), O_RDONLY|O_CLOEXEC|O_BINARY|O_PATH)),
overlay_apk_path_(overlay_apk_path),
target_apk_path_(target_apk_path),
- idmap_last_mod_time_(getFileModDate(idmap_path_.data())) {}
+ idmap_last_mod_time_(getFileModDate(idmap_fd_.get())) {}
std::unique_ptr<LoadedIdmap> LoadedIdmap::Load(StringPiece idmap_path, StringPiece idmap_data) {
ATRACE_CALL();
@@ -368,7 +375,7 @@ std::unique_ptr<LoadedIdmap> LoadedIdmap::Load(StringPiece idmap_path, StringPie
}
bool LoadedIdmap::IsUpToDate() const {
- return idmap_last_mod_time_ == getFileModDate(idmap_path_.c_str());
+ return idmap_last_mod_time_ == getFileModDate(idmap_fd_.get());
}
} // namespace android