summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2021-07-16 14:48:25 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2021-07-17 09:12:26 +0200
commitb1df9c67349cf4cc5be4128d797aefb87f50e38f (patch)
tree171fbccaadecd8fac85e1e6212ce560162fabc7f
parent3545caa5aac59022d5c00d4a0c2a74657cbcae8d (diff)
[API CHANGE] reduce cost of numeric conversion
on a hot path, since we already know the length of these strings. Which requires adding some new variants of our string conversion functions Change-Id: I1877f8f3c72934c07f14eec7e73bbe8d7b0f1808 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/119065 Tested-by: Noel Grandin <noel.grandin@collabora.co.uk> Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
-rw-r--r--include/rtl/string.h45
-rw-r--r--sal/rtl/string.cxx14
-rw-r--r--sal/rtl/strtmpl.hxx10
-rw-r--r--sal/util/sal.map6
-rw-r--r--sax/source/tools/fastattribs.cxx6
5 files changed, 78 insertions, 3 deletions
diff --git a/include/rtl/string.h b/include/rtl/string.h
index d29caf93a718..62fc7ecfb2d0 100644
--- a/include/rtl/string.h
+++ b/include/rtl/string.h
@@ -747,6 +747,31 @@ SAL_DLLPUBLIC sal_Bool SAL_CALL rtl_str_toBoolean(
SAL_DLLPUBLIC sal_Int32 SAL_CALL rtl_str_toInt32(
const char * str, sal_Int16 radix ) SAL_THROW_EXTERN_C();
+/** Interpret a string as a 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 chars to process
+
+ @return
+ the integer value represented by the string, or 0 if the string does
+ not represent a integer.
+
+ @internal
+ @since LibreOffice 7.3
+*/
+SAL_DLLPUBLIC sal_Int32 SAL_CALL rtl_str_toInt32_WithLength(
+ const char * str, sal_Int16 radix, sal_Int32 nStrLength ) SAL_THROW_EXTERN_C();
+
/** Interpret a string as an unsigned integer.
This function cannot be used for language-specific conversion. The string
@@ -863,6 +888,26 @@ SAL_DLLPUBLIC float SAL_CALL rtl_str_toFloat(
SAL_DLLPUBLIC double SAL_CALL rtl_str_toDouble(
const char * str ) SAL_THROW_EXTERN_C();
+/** Interpret a string as a double.
+
+ This function cannot be used for language-specific conversion. The string
+ must be null-terminated.
+
+ @param str
+ a null-terminated string.
+
+ @param nStrLength
+ number of chars to process
+
+ @return
+ the double value represented by the string, or 0.0 if the string does not
+ represent a double.
+
+ @since LibreOffice 7.3
+ */
+SAL_DLLPUBLIC double SAL_CALL rtl_str_toDouble_WithLength(
+ const char * str, sal_Int32 nStrLength ) SAL_THROW_EXTERN_C();
+
/* ======================================================================= */
#ifdef _WIN32
diff --git a/sal/rtl/string.cxx b/sal/rtl/string.cxx
index 94be8029032a..6fc2df75698d 100644
--- a/sal/rtl/string.cxx
+++ b/sal/rtl/string.cxx
@@ -110,6 +110,14 @@ double SAL_CALL rtl_str_toDouble(char const * pStr) SAL_THROW_EXTERN_C()
nullptr, nullptr);
}
+double SAL_CALL rtl_str_toDouble_WithLength(const char* pStr,
+ sal_Int32 nStrLength) SAL_THROW_EXTERN_C()
+{
+ assert(pStr);
+ return rtl_math_stringToDouble(pStr, pStr + nStrLength, '.', 0,
+ nullptr, nullptr);
+}
+
/* ======================================================================= */
static int rtl_ImplGetFastUTF8ByteLen( const sal_Unicode* pStr, sal_Int32 nLen )
@@ -559,6 +567,12 @@ sal_Int32 SAL_CALL rtl_str_toInt32(const char* pStr, sal_Int16 nRadix) SAL_THROW
return rtl::str::toInt32(pStr, nRadix);
}
+sal_Int32 SAL_CALL rtl_str_toInt32_WithLength(const char* pStr, sal_Int16 nRadix,
+ sal_Int32 nStrLength) SAL_THROW_EXTERN_C()
+{
+ return rtl::str::toInt32_WithLength(pStr, nRadix, nStrLength);
+}
+
sal_Int64 SAL_CALL rtl_str_toInt64(const char* pStr, sal_Int16 nRadix) SAL_THROW_EXTERN_C()
{
return rtl::str::toInt64(pStr, nRadix);
diff --git a/sal/rtl/strtmpl.hxx b/sal/rtl/strtmpl.hxx
index 094a1cc1f2ab..493184f92efa 100644
--- a/sal/rtl/strtmpl.hxx
+++ b/sal/rtl/strtmpl.hxx
@@ -914,6 +914,16 @@ sal_Int32 toInt32 ( const IMPL_RTL_STRCODE* pStr,
}
template <typename IMPL_RTL_STRCODE>
+sal_Int32 toInt32_WithLength ( const IMPL_RTL_STRCODE* pStr,
+ sal_Int16 nRadix,
+ sal_Int32 nStrLength)
+
+{
+ assert(pStr);
+ return toInt_WithLength<sal_Int32, sal_uInt32>(pStr, nRadix, nStrLength);
+}
+
+template <typename IMPL_RTL_STRCODE>
sal_Int64 toInt64 ( const IMPL_RTL_STRCODE* pStr,
sal_Int16 nRadix )
{
diff --git a/sal/util/sal.map b/sal/util/sal.map
index 49efb2a436cd..e2339bdc13ac 100644
--- a/sal/util/sal.map
+++ b/sal/util/sal.map
@@ -755,6 +755,12 @@ PRIVATE_1.7 { # LibreOffice 7.1
rtl_uString_newReplaceAllFromIndexUtf16LUtf16L;
} PRIVATE_1.5;
+PRIVATE_1.8 { # LibreOffice 7.3
+ global:
+ rtl_str_toInt32_WithLength;
+ rtl_str_toDouble_WithLength;
+} PRIVATE_1.7;
+
PRIVATE_textenc.1 { # LibreOffice 3.6
global:
_ZN3sal6detail7textenc20convertCharToUnicode*;
diff --git a/sax/source/tools/fastattribs.cxx b/sax/source/tools/fastattribs.cxx
index 554232260aef..9cec32318108 100644
--- a/sax/source/tools/fastattribs.cxx
+++ b/sax/source/tools/fastattribs.cxx
@@ -196,7 +196,7 @@ bool FastAttributeList::getAsInteger( sal_Int32 nToken, sal_Int32 &rInt) const
for (size_t i = 0; i < maAttributeTokens.size(); ++i)
if (maAttributeTokens[i] == nToken)
{
- rInt = rtl_str_toInt32( getFastAttributeValue(i), 10 );
+ rInt = rtl_str_toInt32_WithLength( getFastAttributeValue(i), 10, AttributeValueLength(i) );
return true;
}
return false;
@@ -204,7 +204,7 @@ bool FastAttributeList::getAsInteger( sal_Int32 nToken, sal_Int32 &rInt) const
sal_Int32 FastAttributeList::getAsIntegerByIndex( sal_Int32 nTokenIndex ) const
{
- return rtl_str_toInt32( getFastAttributeValue(nTokenIndex), 10 );
+ return rtl_str_toInt32_WithLength( getFastAttributeValue(nTokenIndex), 10, AttributeValueLength(nTokenIndex) );
}
bool FastAttributeList::getAsDouble( sal_Int32 nToken, double &rDouble) const
@@ -213,7 +213,7 @@ bool FastAttributeList::getAsDouble( sal_Int32 nToken, double &rDouble) const
for (size_t i = 0; i < maAttributeTokens.size(); ++i)
if (maAttributeTokens[i] == nToken)
{
- rDouble = rtl_str_toDouble( getFastAttributeValue(i) );
+ rDouble = rtl_str_toDouble_WithLength( getFastAttributeValue(i), AttributeValueLength(i) );
return true;
}
return false;