Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize use single allocation #76

Merged
merged 1 commit into from
Sep 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions lib/libpcsc-cpp/include/pcsc-cpp/pcsc-cpp-utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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__); \
Expand Down
Loading