sw/source/filter/writer/writer.cxx | 51 ++++++++++++++++++------------------- 1 file changed, 25 insertions(+), 26 deletions(-)
New commits: commit 98a9577c315e7727befa4f2b968bad3bfebe29c5 Author: Matteo Casalin <matteo.casa...@yahoo.com> Date: Thu Aug 15 00:34:37 2013 +0200 Writer::Out(U)Long: share code and avoid a global buffer Change-Id: I6845ff1e74b1cbbedea721bf1d2ad6ac3963bac8 Reviewed-on: https://gerrit.libreoffice.org/5427 Reviewed-by: Michael Stahl <mst...@redhat.com> Tested-by: Michael Stahl <mst...@redhat.com> diff --git a/sw/source/filter/writer/writer.cxx b/sw/source/filter/writer/writer.cxx index 45da4f5..e60d85b 100644 --- a/sw/source/filter/writer/writer.cxx +++ b/sw/source/filter/writer/writer.cxx @@ -35,10 +35,28 @@ using namespace ::com::sun::star; +namespace +{ + +SvStream& lcl_OutLongExt( SvStream& rStrm, sal_uLong nVal, bool bNeg ) +{ + sal_Char aBuf[28]; + + int i = SAL_N_ELEMENTS(aBuf); + aBuf[--i] = 0; + do + { + aBuf[--i] = '0' + static_cast<sal_Char>(nVal % 10); + nVal /= 10; + } while (nVal); + + if (bNeg) + aBuf[--i] = '-'; + + return rStrm << &aBuf[i]; +} -// Stringbuffer for the converted numbers -static sal_Char aNToABuf[] = "0000000000000000000000000"; -#define NTOABUFLEN (sizeof(aNToABuf)) +} typedef std::multimap<sal_uLong, const ::sw::mark::IMark*> SwBookmarkNodeTable; @@ -218,35 +236,16 @@ void Writer::SetStream(SvStream *const pStream) SvStream& Writer::OutLong( SvStream& rStrm, long nVal ) { - // Set the Pointer at the end of the buffer - sal_Char* pStr = aNToABuf + (NTOABUFLEN-1); - - int bNeg = nVal < 0; - if( bNeg ) + const bool bNeg = nVal < 0; + if (bNeg) nVal = -nVal; - do { - *(--pStr) = (sal_Char)(nVal % 10 ) + 48; - nVal /= 10; - } while( nVal ); - - // is the number negative, then in addition - - if( bNeg ) - *(--pStr) = '-'; - - return rStrm << pStr; + return lcl_OutLongExt(rStrm, static_cast<sal_uLong>(nVal), bNeg); } SvStream& Writer::OutULong( SvStream& rStrm, sal_uLong nVal ) { - // Set the Pointer at the end of the buffer - sal_Char* pStr = aNToABuf + (NTOABUFLEN-1); - - do { - *(--pStr) = (sal_Char)(nVal % 10 ) + 48; - nVal /= 10; - } while ( nVal ); - return rStrm << pStr; + return lcl_OutLongExt(rStrm, nVal, false); } _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits