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/misc.cpp | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'libs/androidfw/misc.cpp') 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; } -- cgit v1.2.3-59-g8ed1b