summaryrefslogtreecommitdiff
path: root/include/rtl/string.hxx
diff options
context:
space:
mode:
authorLuboš Luňák <l.lunak@collabora.com>2019-09-13 15:13:55 +0200
committerLuboš Luňák <l.lunak@collabora.com>2019-09-24 12:58:14 +0200
commit2f5f45921b05904a4be1ff633be09c62cb44ff08 (patch)
treeddd0cd5ef0349706f935d8360db88343347639a3 /include/rtl/string.hxx
parenta7d40f575463467698df76f041e558cb3bea7c85 (diff)
support O(U)String::number() for fast string concatenation
When I did the fast string concatenation, I didn't add any support for number(), which simply returned a O(U)String, and so it did the extra allocation/deallocation, although that could be avoided. In order to support this, number() now returns a special temporary return type, similarly to O(U)StringConcat, which allows delaying the concatenation the same way. Also similarly, the change of the return type in some cases requires explicit cast to the actual string type. Usage of OString::getStr() is so extensive in the codebase that I actually added it to the helper class, after that it's only relatively few cases. Change-Id: Iba6e158010e1e458089698c426803052b6f46031 Reviewed-on: https://gerrit.libreoffice.org/78873 Tested-by: Jenkins Reviewed-by: Luboš Luňák <l.lunak@collabora.com>
Diffstat (limited to 'include/rtl/string.hxx')
-rw-r--r--include/rtl/string.hxx64
1 files changed, 64 insertions, 0 deletions
diff --git a/include/rtl/string.hxx b/include/rtl/string.hxx
index d06a1b727394..68450da21fa9 100644
--- a/include/rtl/string.hxx
+++ b/include/rtl/string.hxx
@@ -280,6 +280,15 @@ public:
*end = '\0';
}
}
+
+ /**
+ @overload
+ @internal
+ */
+ template< typename T >
+ OString( OStringNumber< T >&& n )
+ : OString( n.buf, n.length )
+ {}
#endif
#ifdef LIBO_INTERNAL_ONLY
@@ -383,6 +392,25 @@ public:
}
template<typename T1, typename T2> void operator +=(
OStringConcat<T1, T2> &&) && = delete;
+
+ /**
+ @overload
+ @internal
+ */
+ template< typename T >
+ OString& operator+=( OStringNumber< T >&& n ) & {
+ sal_Int32 l = n.length;
+ if( l == 0 )
+ return *this;
+ l += pData->length;
+ rtl_string_ensureCapacity( &pData, l );
+ char* end = addDataHelper( pData->buffer + pData->length, n.buf, n.length );
+ *end = '\0';
+ pData->length = l;
+ return *this;
+ }
+ template<typename T> void operator +=(
+ OStringNumber<T> &&) && = delete;
#endif
/**
@@ -1602,6 +1630,41 @@ public:
return rtl_str_toDouble( pData->buffer );
}
+#ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
+
+ static OStringNumber< int > number( int i, sal_Int16 radix = 10 )
+ {
+ return OStringNumber< int >( i, radix );
+ }
+ static OStringNumber< long long > number( long long ll, sal_Int16 radix = 10 )
+ {
+ return OStringNumber< long long >( ll, radix );
+ }
+ static OStringNumber< unsigned long long > number( unsigned long long ll, sal_Int16 radix = 10 )
+ {
+ return OStringNumber< unsigned long long >( ll, radix );
+ }
+ static OStringNumber< unsigned long long > number( unsigned int i, sal_Int16 radix = 10 )
+ {
+ return number( static_cast< unsigned long long >( i ), radix );
+ }
+ static OStringNumber< long long > number( long i, sal_Int16 radix = 10)
+ {
+ return number( static_cast< long long >( i ), radix );
+ }
+ static OStringNumber< unsigned long long > number( unsigned long i, sal_Int16 radix = 10 )
+ {
+ return number( static_cast< unsigned long long >( i ), radix );
+ }
+ static OStringNumber< float > number( float f )
+ {
+ return OStringNumber< float >( f );
+ }
+ static OStringNumber< double > number( double d )
+ {
+ return OStringNumber< double >( d );
+ }
+#else
/**
Returns the string representation of the integer argument.
@@ -1686,6 +1749,7 @@ public:
rtl_string_newFromStr_WithLength( &pNewData, aBuf, rtl_str_valueOfDouble( aBuf, d ) );
return OString( pNewData, SAL_NO_ACQUIRE );
}
+#endif
/**
Returns the string representation of the sal_Bool argument.