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>
This commit is contained in:
parent
877d0c2c21
commit
ab35d2ded1
@ -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
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------- */
|
||||
|
@ -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*;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user