include/rtl/stringconcat.hxx | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-)
New commits: commit d57d001e277108bdde0bed5740813bde9f2088ac Author: Mike Kaganski <mike.kagan...@collabora.com> AuthorDate: Fri Mar 21 15:05:17 2025 +0500 Commit: Mike Kaganski <mike.kagan...@collabora.com> CommitDate: Fri Mar 21 14:02:36 2025 +0100 Simplify ToStringHelper a bit This helped me to workaround a very mysterious problem, that appeared in non-debug build (using VS2022 17.14.0 preview 2.0), where a concat in cppuhelper::ServiceManager::addSingletonContextEntries looking like "/singletons/" + u"com.sun.star.configuration.theDefaultProvider"_ustr gave "/single/sincom.sun.star.configuration.theDefaultProvider". The problem has survived three 'make clean' and rebuild. No idea what was the reason: maybe a specific VS (preview) version's optimization bug? Or do we do some spooky memory rewrite somewhere, which happened to surface in this case? The workaround helping me is obviously because of some code reorganization in the compiler, not caused by functional change. (Just for completeness: another workaround was to replace the literal "/singletons/" with u"/singletons/", which also helped.) Change-Id: If01823ccafb6b4c44f99f9a39d849d7c425cc069 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/183195 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com> diff --git a/include/rtl/stringconcat.hxx b/include/rtl/stringconcat.hxx index 0bed28ac810c..216670e0d635 100644 --- a/include/rtl/stringconcat.hxx +++ b/include/rtl/stringconcat.hxx @@ -16,6 +16,7 @@ #include "rtl/string.h" #include "rtl/ustring.h" +#include <algorithm> #include <cassert> #include <cstddef> #include <memory> @@ -82,14 +83,6 @@ C* addDataHelper( C* buffer, const C* data, std::size_t length ) return buffer + length; } -inline -sal_Unicode* addDataLiteral( sal_Unicode* buffer, const char* data, std::size_t length ) -{ - for( std::size_t i = 0; i != length; ++i ) - *buffer++ = *data++; - return buffer; -} - template <typename C> inline C* addDataString( C* buffer, const C* str ) { @@ -126,7 +119,7 @@ struct ToStringHelper< const char[ N ] > { static std::size_t length( const char str[ N ] ) { (void)str; assert( strlen( str ) == N - 1 ); return N - 1; } char* operator()( char* buffer, const char str[ N ] ) const { return addDataHelper( buffer, str, N - 1 ); } - sal_Unicode* operator()( sal_Unicode* buffer, const char str[ N ] ) const { return addDataLiteral( buffer, str, N - 1 ); } + sal_Unicode* operator()( sal_Unicode* buffer, const char str[ N ] ) const { return std::copy_n( str, N - 1, buffer ); } }; template<>