From fc6bca5cb6b5dbc1a2778dd6b743d2abf39cb00d Mon Sep 17 00:00:00 2001 From: Simon Rozman Date: Fri, 5 Jan 2024 22:58:03 +0100 Subject: [PATCH] dyld: Write directly into std::string buffer This removes extra memory allocation. Signed-off-by: Simon Rozman --- include/MacStd/dyld.hpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/MacStd/dyld.hpp b/include/MacStd/dyld.hpp index 84be977..87b8aaa 100644 --- a/include/MacStd/dyld.hpp +++ b/include/MacStd/dyld.hpp @@ -24,10 +24,10 @@ inline int _NSGetExecutablePath(std::string& path) return 0; } if (result == -1) { - std::unique_ptr heap_buffer(new char[capacity]); - result = _NSGetExecutablePath(heap_buffer.get(), &capacity); + path.resize(capacity - 1); + result = _NSGetExecutablePath(&path[0], &capacity); if (result == 0) { - path = heap_buffer.get(); + path.resize(strnlen(path.data(), path.size())); return 0; } }