From af5da6f53c8469752a3e7610d495859c4ddcab7c Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Fri, 22 Oct 2021 21:53:46 +0200 Subject: [PATCH] Move inline string copy helpers to a separate header. --- client/TracyCallstack.cpp | 39 +-------------------------- client/TracyStringHelpers.hpp | 50 +++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 38 deletions(-) create mode 100644 client/TracyStringHelpers.hpp diff --git a/client/TracyCallstack.cpp b/client/TracyCallstack.cpp index ac0abacc..01202c76 100644 --- a/client/TracyCallstack.cpp +++ b/client/TracyCallstack.cpp @@ -3,6 +3,7 @@ #include #include "TracyCallstack.hpp" #include "TracyFastVector.hpp" +#include "TracyStringHelpers.hpp" #include "../common/TracyAlloc.hpp" #include "../common/TracyStackFrames.hpp" #include "TracyDebug.hpp" @@ -54,44 +55,6 @@ extern "C" namespace tracy { -static inline char* CopyString( const char* src, size_t sz ) -{ - assert( strlen( src ) == sz ); - auto dst = (char*)tracy_malloc( sz + 1 ); - memcpy( dst, src, sz ); - dst[sz] = '\0'; - return dst; -} - -static inline char* CopyString( const char* src ) -{ - const auto sz = strlen( src ); - auto dst = (char*)tracy_malloc( sz + 1 ); - memcpy( dst, src, sz ); - dst[sz] = '\0'; - return dst; -} - -static inline char* CopyStringFast( const char* src, size_t sz ) -{ - assert( strlen( src ) == sz ); - auto dst = (char*)tracy_malloc_fast( sz + 1 ); - memcpy( dst, src, sz ); - dst[sz] = '\0'; - return dst; -} - -static inline char* CopyStringFast( const char* src ) -{ - const auto sz = strlen( src ); - auto dst = (char*)tracy_malloc_fast( sz + 1 ); - memcpy( dst, src, sz ); - dst[sz] = '\0'; - return dst; -} - - - #if TRACY_HAS_CALLSTACK == 1 enum { MaxCbTrace = 16 }; diff --git a/client/TracyStringHelpers.hpp b/client/TracyStringHelpers.hpp new file mode 100644 index 00000000..7f9efbed --- /dev/null +++ b/client/TracyStringHelpers.hpp @@ -0,0 +1,50 @@ +#ifndef __TRACYSTRINGHELPERS_HPP__ +#define __TRACYSTRINGHELPERS_HPP__ + +#include +#include + +#include "../common/TracyAlloc.hpp" + +namespace tracy +{ + +static inline char* CopyString( const char* src, size_t sz ) +{ + assert( strlen( src ) == sz ); + auto dst = (char*)tracy_malloc( sz + 1 ); + memcpy( dst, src, sz ); + dst[sz] = '\0'; + return dst; +} + +static inline char* CopyString( const char* src ) +{ + const auto sz = strlen( src ); + auto dst = (char*)tracy_malloc( sz + 1 ); + memcpy( dst, src, sz ); + dst[sz] = '\0'; + return dst; +} + +static inline char* CopyStringFast( const char* src, size_t sz ) +{ + assert( strlen( src ) == sz ); + auto dst = (char*)tracy_malloc_fast( sz + 1 ); + memcpy( dst, src, sz ); + dst[sz] = '\0'; + return dst; +} + +static inline char* CopyStringFast( const char* src ) +{ + const auto sz = strlen( src ); + auto dst = (char*)tracy_malloc_fast( sz + 1 ); + memcpy( dst, src, sz ); + dst[sz] = '\0'; + return dst; +} + +} + +#endif