summaryrefslogtreecommitdiff
path: root/libs/androidfw/misc.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/misc.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/misc.cpp')
-rw-r--r--libs/androidfw/misc.cpp20
1 files changed, 15 insertions, 5 deletions
diff --git a/libs/androidfw/misc.cpp b/libs/androidfw/misc.cpp
index d3949e9cf69f..93dcaf549a90 100644
--- a/libs/androidfw/misc.cpp
+++ b/libs/androidfw/misc.cpp
@@ -76,13 +76,23 @@ FileType getFileType(const char* fileName)
/*
* Get a file's modification date.
*/
-time_t getFileModDate(const char* fileName)
-{
+time_t getFileModDate(const char* fileName) {
struct stat sb;
+ if (stat(fileName, &sb) < 0) {
+ return (time_t)-1;
+ }
+ return sb.st_mtime;
+}
- if (stat(fileName, &sb) < 0)
- return (time_t) -1;
-
+time_t getFileModDate(int fd) {
+ struct stat sb;
+ if (fstat(fd, &sb) < 0) {
+ return (time_t)-1;
+ }
+ if (sb.st_nlink <= 0) {
+ errno = ENOENT;
+ return (time_t)-1;
+ }
return sb.st_mtime;
}