aboutsummaryrefslogtreecommitdiff
path: root/zencore/filesystem.cpp
diff options
context:
space:
mode:
authorDan Engelbrecht <[email protected]>2022-12-08 14:44:14 +0100
committerGitHub <[email protected]>2022-12-08 05:44:14 -0800
commit85c411df89737c153528c1ef0d99305bd2e060de (patch)
tree437e90dbececb4609fb7984dd657d5488aab52f8 /zencore/filesystem.cpp
parentFix http parsing crash (#205) (diff)
downloadzen-85c411df89737c153528c1ef0d99305bd2e060de.tar.xz
zen-85c411df89737c153528c1ef0d99305bd2e060de.zip
Path from handle perf improvement (#206)
* Read recorded requests to memory before parsing This will more accurately simulate how requests comes in from a client * Make a fast path for GetFinalPathNameByHandleW Try to get the path with a fixes size buffer first to avoid always doing two calls to GetFinalPathNameByHandleW
Diffstat (limited to 'zencore/filesystem.cpp')
-rw-r--r--zencore/filesystem.cpp12
1 files changed, 10 insertions, 2 deletions
diff --git a/zencore/filesystem.cpp b/zencore/filesystem.cpp
index 1e4a52638..a2442a134 100644
--- a/zencore/filesystem.cpp
+++ b/zencore/filesystem.cpp
@@ -976,19 +976,27 @@ PathFromHandle(void* NativeHandle)
}
};
- DWORD RequiredLengthIncludingNul = GetFinalPathNameByHandleWRetry(NativeHandle, nullptr, 0, FILE_NAME_OPENED);
+ static const DWORD PathDataSize = 512;
+ wchar_t PathData[PathDataSize];
+ DWORD RequiredLengthIncludingNul = GetFinalPathNameByHandleWRetry(NativeHandle, PathData, PathDataSize, FILE_NAME_OPENED);
if (RequiredLengthIncludingNul == 0)
{
ThrowLastError(fmt::format("failed to get path from file handle {}", NativeHandle));
}
+ if (RequiredLengthIncludingNul < PathDataSize)
+ {
+ std::wstring FullPath(PathData, gsl::narrow<size_t>(RequiredLengthIncludingNul));
+ return FullPath;
+ }
+
std::wstring FullPath;
FullPath.resize(RequiredLengthIncludingNul - 1);
const DWORD FinalLength = GetFinalPathNameByHandleWRetry(NativeHandle, FullPath.data(), RequiredLengthIncludingNul, FILE_NAME_OPENED);
ZEN_UNUSED(FinalLength);
-
return FullPath;
+
#elif ZEN_PLATFORM_LINUX
char Link[PATH_MAX];
char Path[64];