diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2019-10-30 08:41:43 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2019-10-31 07:02:09 +0100 |
commit | ab35d2ded153b0129fed16f9a7e882c8600933e6 (patch) | |
tree | 13f1776117f743c34761b6a31ca93f80020e20d3 | |
parent | 877d0c2c211067e8c1b5fdff0f6d9703c94767e9 (diff) |
tdf#125688 speed up load of change-tracking ODS
by 10%, by avoiding an OUString construction in a hot path
through
XMLTextColumnContext_Impl::XMLTextColumnContext_Impl
-> sax::Convert::convertNumber
Also changed XMLTextAnimationStepPropertyHdl::importXML
to take advantage of the modified convertNumber passing
convention.
Change-Id: I4e5503dbb094c88a09af8b6dc8c22b6c53f9eb75
Reviewed-on: https://gerrit.libreoffice.org/81726
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
-rw-r--r-- | include/rtl/string.h | 25 | ||||
-rw-r--r-- | include/rtl/ustring.h | 25 | ||||
-rw-r--r-- | include/sax/tools/converter.hxx | 4 | ||||
-rw-r--r-- | sal/rtl/strtmpl.cxx | 24 | ||||
-rw-r--r-- | sal/util/sal.map | 6 | ||||
-rw-r--r-- | sax/source/tools/converter.cxx | 36 | ||||
-rw-r--r-- | xmloff/source/draw/propimp0.cxx | 2 | ||||
-rw-r--r-- | xmloff/source/text/XMLTextColumnsContext.cxx | 7 |
8 files changed, 96 insertions, 33 deletions
diff --git a/include/rtl/string.h b/include/rtl/string.h index 4996e1d07b4d..81322b186875 100644 --- a/include/rtl/string.h +++ b/include/rtl/string.h @@ -783,6 +783,31 @@ SAL_DLLPUBLIC sal_uInt32 SAL_CALL rtl_str_toUInt32( SAL_DLLPUBLIC sal_Int64 SAL_CALL rtl_str_toInt64( const sal_Char * str, sal_Int16 radix ) SAL_THROW_EXTERN_C(); +/** Interpret a string as a long integer. + + This function cannot be used for language-specific conversion. The string + must be null-terminated. + + @param str + a null-terminated string. + + @param radix + the radix. Must be between RTL_STR_MIN_RADIX (2) and RTL_STR_MAX_RADIX + (36), inclusive. + + @param nStrLength + number of sal_Chars to process + + @return + the long integer value represented by the string, or 0 if the string does + not represent a long integer. + + @internal + @since LibreOffice 6.4 +*/ +SAL_DLLPUBLIC sal_Int64 SAL_CALL rtl_str_toInt64_WithLength( + const sal_Char * str, sal_Int16 radix, sal_Int32 nStrLength ) SAL_THROW_EXTERN_C(); + /** Interpret a string as an unsigned long integer. This function cannot be used for language-specific conversion. The string diff --git a/include/rtl/ustring.h b/include/rtl/ustring.h index 35e4a7d4ad67..5e481c21c4c4 100644 --- a/include/rtl/ustring.h +++ b/include/rtl/ustring.h @@ -1113,6 +1113,31 @@ SAL_DLLPUBLIC sal_uInt32 SAL_CALL rtl_ustr_toUInt32( SAL_DLLPUBLIC sal_Int64 SAL_CALL rtl_ustr_toInt64( const sal_Unicode * str, sal_Int16 radix ) SAL_THROW_EXTERN_C(); +/** Interpret a string as a long integer. + + This function cannot be used for language-specific conversion. The string + must be null-terminated. + + @param str + a null-terminated string. + + @param radix + the radix. Must be between RTL_USTR_MIN_RADIX (2) and RTL_USTR_MAX_RADIX + (36), inclusive. + + @param nStrLength + number of chars to process + + @return + the long integer value represented by the string, or 0 if the string does + not represent a long integer. + + @internal + @since LibreOffice 6.4 +*/ +SAL_DLLPUBLIC sal_Int64 SAL_CALL rtl_ustr_toInt64_WithLength( + const sal_Unicode * str, sal_Int16 radix, sal_Int32 nStrLength ) SAL_THROW_EXTERN_C(); + /** Interpret a string as an unsigned long integer. This function cannot be used for language-specific conversion. The string diff --git a/include/sax/tools/converter.hxx b/include/sax/tools/converter.hxx index d1dbdac62d54..a372360f6d8d 100644 --- a/include/sax/tools/converter.hxx +++ b/include/sax/tools/converter.hxx @@ -112,13 +112,13 @@ public: /** convert string to number with optional min and max values */ static bool convertNumber( sal_Int32& rValue, - const OUString& rString, + std::u16string_view aString, sal_Int32 nMin = SAL_MIN_INT32, sal_Int32 nMax = SAL_MAX_INT32 ); /** convert string to number with optional min and max values */ static bool convertNumber64(sal_Int64& rValue, - const OUString& rString, + std::u16string_view aString, sal_Int64 nMin = SAL_MIN_INT64, sal_Int64 nMax = SAL_MAX_INT64); diff --git a/sal/rtl/strtmpl.cxx b/sal/rtl/strtmpl.cxx index 3cc4d9927274..4e6035d478e2 100644 --- a/sal/rtl/strtmpl.cxx +++ b/sal/rtl/strtmpl.cxx @@ -989,20 +989,23 @@ sal_Bool SAL_CALL IMPL_RTL_STRNAME( toBoolean )( const IMPL_RTL_STRCODE* pStr ) /* ----------------------------------------------------------------------- */ namespace { - template<typename T, typename U> T IMPL_RTL_STRNAME( toInt )( const IMPL_RTL_STRCODE* pStr, - sal_Int16 nRadix ) + template<typename T, typename U> T IMPL_RTL_STRNAME( toInt_WithLength )( const IMPL_RTL_STRCODE* pStr, + sal_Int16 nRadix, + sal_Int32 nStrLength ) { static_assert(std::numeric_limits<T>::is_signed, "is signed"); assert( nRadix >= RTL_STR_MIN_RADIX && nRadix <= RTL_STR_MAX_RADIX ); + assert( nStrLength >= 0 ); bool bNeg; sal_Int16 nDigit; U n = 0; + const IMPL_RTL_STRCODE* pEnd = pStr + nStrLength; if ( (nRadix < RTL_STR_MIN_RADIX) || (nRadix > RTL_STR_MAX_RADIX) ) nRadix = 10; /* Skip whitespaces */ - while ( *pStr && rtl_ImplIsWhitespace( IMPL_RTL_USTRCODE( *pStr ) ) ) + while ( pStr != pEnd && rtl_ImplIsWhitespace( IMPL_RTL_USTRCODE( *pStr ) ) ) pStr++; if ( *pStr == '-' ) @@ -1039,7 +1042,7 @@ namespace { nMod = std::numeric_limits<T>::max() % nRadix; } - while ( *pStr ) + while ( pStr != pEnd ) { nDigit = rtl_ImplGetDigit( IMPL_RTL_USTRCODE( *pStr ), nRadix ); if ( nDigit < 0 ) @@ -1067,7 +1070,7 @@ sal_Int32 SAL_CALL IMPL_RTL_STRNAME( toInt32 )( const IMPL_RTL_STRCODE* pStr, SAL_THROW_EXTERN_C() { assert(pStr); - return IMPL_RTL_STRNAME( toInt )<sal_Int32, sal_uInt32>(pStr, nRadix); + return IMPL_RTL_STRNAME( toInt_WithLength )<sal_Int32, sal_uInt32>(pStr, nRadix, IMPL_RTL_STRNAME( getLength )(pStr)); } sal_Int64 SAL_CALL IMPL_RTL_STRNAME( toInt64 )( const IMPL_RTL_STRCODE* pStr, @@ -1075,7 +1078,16 @@ sal_Int64 SAL_CALL IMPL_RTL_STRNAME( toInt64 )( const IMPL_RTL_STRCODE* pStr, SAL_THROW_EXTERN_C() { assert(pStr); - return IMPL_RTL_STRNAME( toInt )<sal_Int64, sal_uInt64>(pStr, nRadix); + return IMPL_RTL_STRNAME( toInt_WithLength )<sal_Int64, sal_uInt64>(pStr, nRadix, IMPL_RTL_STRNAME( getLength )(pStr)); +} + +sal_Int64 SAL_CALL IMPL_RTL_STRNAME( toInt64_WithLength )( const IMPL_RTL_STRCODE* pStr, + sal_Int16 nRadix, + sal_Int32 nStrLength) + SAL_THROW_EXTERN_C() +{ + assert(pStr); + return IMPL_RTL_STRNAME( toInt_WithLength )<sal_Int64, sal_uInt64>(pStr, nRadix, nStrLength); } /* ----------------------------------------------------------------------- */ diff --git a/sal/util/sal.map b/sal/util/sal.map index 9292d50ca423..48d76b1a3802 100644 --- a/sal/util/sal.map +++ b/sal/util/sal.map @@ -743,6 +743,12 @@ PRIVATE_1.5 { # LibreOffice 6.1 rtl_alloc_preInit; } PRIVATE_1.4; +PRIVATE_1.6 { # LibreOffice 6.4 + global: + rtl_str_toInt64_WithLength; + rtl_ustr_toInt64_WithLength; +} PRIVATE_1.5; + PRIVATE_textenc.1 { # LibreOffice 3.6 global: _ZN3sal6detail7textenc20convertCharToUnicode*; diff --git a/sax/source/tools/converter.cxx b/sax/source/tools/converter.cxx index 15f8abbde4e3..a0790ce0e114 100644 --- a/sax/source/tools/converter.cxx +++ b/sax/source/tools/converter.cxx @@ -514,12 +514,12 @@ void Converter::convertColor( OUStringBuffer& rBuffer, sal_Int32 nColor ) /** convert string to number with optional min and max values */ bool Converter::convertNumber( sal_Int32& rValue, - const OUString& rString, + std::u16string_view aString, sal_Int32 nMin, sal_Int32 nMax ) { rValue = 0; sal_Int64 nNumber = 0; - bool bRet = convertNumber64(nNumber,rString,nMin,nMax); + bool bRet = convertNumber64(nNumber,aString,nMin,nMax); if ( bRet ) rValue = static_cast<sal_Int32>(nNumber); return bRet; @@ -527,32 +527,32 @@ bool Converter::convertNumber( sal_Int32& rValue, /** convert string to 64-bit number with optional min and max values */ bool Converter::convertNumber64( sal_Int64& rValue, - const OUString& rString, + std::u16string_view aString, sal_Int64 nMin, sal_Int64 nMax ) { sal_Int32 nPos = 0; - sal_Int32 const nLen = rString.getLength(); + sal_Int32 const nLen = aString.size(); // skip white space - while( (nPos < nLen) && (rString[nPos] <= ' ') ) + while( (nPos < nLen) && (aString[nPos] <= ' ') ) nPos++; - OUStringBuffer sNumber; + sal_Int32 nNumberStartPos = nPos; - if( nPos < nLen && '-' == rString[nPos] ) + if( nPos < nLen && '-' == aString[nPos] ) { - sNumber.append(rString[nPos++]); + nPos++; } // get number while( nPos < nLen && - '0' <= rString[nPos] && - '9' >= rString[nPos] ) + '0' <= aString[nPos] && + '9' >= aString[nPos] ) { - sNumber.append(rString[nPos++]); + nPos++; } - rValue = sNumber.toString().toInt64(); + rValue = rtl_ustr_toInt64_WithLength(aString.data() + nNumberStartPos, 10, nPos - nNumberStartPos); if( rValue < nMin ) rValue = nMin; @@ -952,18 +952,11 @@ readUnsignedNumber(const OUString & rString, { sal_Int32 nPos(io_rnPos); - OUStringBuffer aNumber; while (nPos < rString.getLength()) { const sal_Unicode c = rString[nPos]; - if (('0' <= c) && (c <= '9')) - { - aNumber.append(c); - } - else - { + if (!(('0' <= c) && (c <= '9'))) break; - } ++nPos; } @@ -973,7 +966,8 @@ readUnsignedNumber(const OUString & rString, return R_NOTHING; } - const sal_Int64 nTemp = aNumber.toString().toInt64(); + const sal_Int64 nTemp = rtl_ustr_toInt64_WithLength(rString.getStr() + io_rnPos, 10, nPos - io_rnPos); + const bool bOverflow = (nTemp >= SAL_MAX_INT32); io_rnPos = nPos; diff --git a/xmloff/source/draw/propimp0.cxx b/xmloff/source/draw/propimp0.cxx index cbd909e3c7c9..fe796539b5b5 100644 --- a/xmloff/source/draw/propimp0.cxx +++ b/xmloff/source/draw/propimp0.cxx @@ -186,7 +186,7 @@ bool XMLTextAnimationStepPropertyHdl::importXML( sal_Int32 nPos = rStrImpValue.indexOf( aPX ); if( nPos != -1 ) { - if (::sax::Converter::convertNumber(nValue, rStrImpValue.copy(0, nPos))) + if (::sax::Converter::convertNumber(nValue, std::u16string_view(rStrImpValue).substr(0, nPos))) { rValue <<= sal_Int16( -nValue ); bRet = true; diff --git a/xmloff/source/text/XMLTextColumnsContext.cxx b/xmloff/source/text/XMLTextColumnsContext.cxx index 66798582b27f..b62b66fde137 100644 --- a/xmloff/source/text/XMLTextColumnsContext.cxx +++ b/xmloff/source/text/XMLTextColumnsContext.cxx @@ -137,10 +137,11 @@ XMLTextColumnContext_Impl::XMLTextColumnContext_Impl( sal_Int32 nPos = rValue.indexOf( '*' ); if( nPos != -1 && nPos+1 == rValue.getLength() ) { - OUString sTmp( rValue.copy( 0, nPos ) ); if (::sax::Converter::convertNumber( - nVal, sTmp, 0, USHRT_MAX)) - aColumn.Width = nVal; + nVal, + std::u16string_view(rValue).substr(0, nPos), + 0, USHRT_MAX)) + aColumn.Width = nVal; } } break; |