From 477a75762e569ea8612542b9c583db0f1a2b1649 Mon Sep 17 00:00:00 2001 From: Raul Metsma Date: Sat, 29 Jun 2024 23:07:57 +0300 Subject: [PATCH] Optimize use single allocation Signed-off-by: Raul Metsma --- lib/libpcsc-cpp/include/pcsc-cpp/pcsc-cpp-utils.hpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/libpcsc-cpp/include/pcsc-cpp/pcsc-cpp-utils.hpp b/lib/libpcsc-cpp/include/pcsc-cpp/pcsc-cpp-utils.hpp index f768808..c64ecba 100644 --- a/lib/libpcsc-cpp/include/pcsc-cpp/pcsc-cpp-utils.hpp +++ b/lib/libpcsc-cpp/include/pcsc-cpp/pcsc-cpp-utils.hpp @@ -43,23 +43,23 @@ inline std::string int2hexstr(const T value) /** Remove absolute path prefix until 'src' from the given path, '/path/to/src/main.cpp' becomes * 'src/main.cpp'. */ -inline std::string removeAbsolutePathPrefix(const std::string& filePath) +inline std::string removeAbsolutePathPrefix(std::string filePath) { const auto lastSrc = filePath.rfind("src"); - return lastSrc == std::string::npos ? filePath : filePath.substr(lastSrc); + return lastSrc == std::string::npos ? std::move(filePath) : filePath.erase(0, lastSrc); } } // namespace pcsc_cpp #define THROW_WITH_CALLER_INFO(ExceptionType, message, file, line, func) \ throw ExceptionType(std::string(message) + " in " + pcsc_cpp::removeAbsolutePathPrefix(file) \ - + ':' + std::to_string(line) + ':' + func) + + ':' + std::to_string(line) + ':' + (func)) #define THROW(ExceptionType, message) \ THROW_WITH_CALLER_INFO(ExceptionType, message, __FILE__, __LINE__, __func__) #define REQUIRE_NON_NULL(val) \ - if (!val) { \ + if (!(val)) { \ throw std::logic_error("Null " + std::string(#val) + " in " \ + pcsc_cpp::removeAbsolutePathPrefix(__FILE__) + ':' \ + std::to_string(__LINE__) + ':' + __func__); \