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.kaganski@collabora.com>
This commit is contained in:
Mike Kaganski 2025-03-21 15:05:17 +05:00
parent 6a7e2f4ba5
commit d57d001e27

View File

@ -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<>