From: Clemens Wasser Date: Wed, 20 Mar 2024 12:40:58 +0000 (+0100) Subject: Optimize read_file size_hint on Windows X-Git-Tag: v4.10~71^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0552beaf4627ac7297f19fbcd788554bb13b05ce;p=thirdparty%2Fccache.git Optimize read_file size_hint on Windows --- diff --git a/src/ccache/util/file.cpp b/src/ccache/util/file.cpp index 13daa537..5ea8cbe9 100644 --- a/src/ccache/util/file.cpp +++ b/src/ccache/util/file.cpp @@ -61,6 +61,11 @@ #include #include +#ifdef _WIN32 +# include +# include +#endif + namespace fs = util::filesystem; using pstr = util::PathString; @@ -229,6 +234,7 @@ template tl::expected read_file(const fs::path& path, size_t size_hint) { +#ifndef _WIN32 if (size_hint == 0) { DirEntry de(path); if (!de) { @@ -236,6 +242,7 @@ read_file(const fs::path& path, size_t size_hint) } size_hint = de.size(); } +#endif if (size_hint > std::numeric_limits::max() / 4) { // Too large value on a 32-bit system won't work well, better bail. @@ -255,6 +262,15 @@ read_file(const fs::path& path, size_t size_hint) return tl::unexpected(strerror(errno)); } +#ifdef _WIN32 + if (size_hint == 0) { + LARGE_INTEGER file_size; + GetFileSizeEx(reinterpret_cast(_get_osfhandle(fd.get())), + &file_size); + size_hint = (size_t)file_size.QuadPart; + } +#endif + int64_t ret = 0; size_t pos = 0; T result;