[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
diff --git a/libs/androidfw/Idmap.cpp b/libs/androidfw/Idmap.cpp
index 5f98b8f..9824190 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 @@
}
} // 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 @@
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 @@
}
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