summaryrefslogtreecommitdiff
path: root/sal
diff options
context:
space:
mode:
authorMike Kaganski <mike.kaganski@collabora.com>2021-09-29 23:22:01 +0200
committerMike Kaganski <mike.kaganski@collabora.com>2021-09-30 07:13:50 +0200
commita4d865e4d82d44cd75f24c5385d44de8f4fcc62f (patch)
treecf61343b988a5bf72c29f6b09b83e9dceba98dbf /sal
parentcdc1f41d4530ad3ec553d90dad803bc5b940656c (diff)
Avoid reversing the buffer
Fill it in the correct order, starting from the middle Change-Id: Id35475e391d771d6c23252124a92825b24b55e0c Reviewed-on: https://gerrit.libreoffice.org/c/core/+/122853 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'sal')
-rw-r--r--sal/rtl/math.cxx23
1 files changed, 9 insertions, 14 deletions
diff --git a/sal/rtl/math.cxx b/sal/rtl/math.cxx
index b36aef117136..0cd53cd3902a 100644
--- a/sal/rtl/math.cxx
+++ b/sal/rtl/math.cxx
@@ -358,14 +358,13 @@ void doubleToString(typename T::String ** pResult,
sal_Int64 nRounding = static_cast< sal_Int64 >(getN10Exp(-nDecPlaces - 1));
const sal_Int64 nTemp = (nInt / nRounding + 5) / 10;
nInt = nTemp * 10 * nRounding;
- nDecPlaces = 0;
}
// Max 1 sign, 16 integer digits, 15 group separators, 1 decimal
// separator, 15 decimals digits.
typename T::Char aBuf[64];
- typename T::Char * pBuf = aBuf;
- typename T::Char * p = pBuf;
+ typename T::Char* pEnd = aBuf + 40;
+ typename T::Char* pStart = pEnd;
// Backward fill.
size_t nGrouping = 0;
@@ -374,10 +373,10 @@ void doubleToString(typename T::String ** pResult,
{
typename T::Char nDigit = nInt % 10;
nInt /= 10;
- *p++ = nDigit + '0';
+ *--pStart = nDigit + '0';
if (pGroups && pGroups[nGrouping] == ++nGroupDigits && nInt > 0 && cGroupSeparator)
{
- *p++ = cGroupSeparator;
+ *--pStart = cGroupSeparator;
if (pGroups[nGrouping+1])
++nGrouping;
nGroupDigits = 0;
@@ -385,23 +384,19 @@ void doubleToString(typename T::String ** pResult,
}
while (nInt > 0);
if (bSign)
- *p++ = '-';
-
- // Reverse buffer content.
- std::reverse(pBuf, p);
+ *--pStart = '-';
// Append decimals.
if (nDecPlaces > 0)
{
- *p++ = cDecSeparator;
- while (nDecPlaces--)
- *p++ = '0';
+ *pEnd++ = cDecSeparator;
+ pEnd = std::fill_n(pEnd, nDecPlaces, '0');
}
if (!pResultCapacity)
- T::createString(pResult, pBuf, p - pBuf);
+ T::createString(pResult, pStart, pEnd - pStart);
else
- T::appendChars(pResult, pResultCapacity, &nResultOffset, pBuf, p - pBuf);
+ T::appendChars(pResult, pResultCapacity, &nResultOffset, pStart, pEnd - pStart);
return;
}