diff options
author | Luboš Luňák <l.lunak@collabora.com> | 2022-03-01 13:57:26 +0100 |
---|---|---|
committer | Luboš Luňák <l.lunak@collabora.com> | 2022-03-01 21:32:34 +0100 |
commit | 09558e2f45e27d572fd261562c884c2d2cc896a7 (patch) | |
tree | a4a29997798c5ed4d84bedd645a76e55614372ed /svtools/source/svrtf | |
parent | b871d057c45fdd231aa5e1d2b94e7d0a039f4292 (diff) |
avoid a temporary buffer, append to the resulting one (tdf#145862)
It doesn't seem to make a visible performance difference though.
Change-Id: Iec56f4f484dbebcc216308d17422151424d0697c
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/130790
Tested-by: Jenkins
Reviewed-by: Luboš Luňák <l.lunak@collabora.com>
Diffstat (limited to 'svtools/source/svrtf')
-rw-r--r-- | svtools/source/svrtf/parrtf.cxx | 38 |
1 files changed, 14 insertions, 24 deletions
diff --git a/svtools/source/svrtf/parrtf.cxx b/svtools/source/svrtf/parrtf.cxx index 719401d342fe..c6dcef7a0b69 100644 --- a/svtools/source/svrtf/parrtf.cxx +++ b/svtools/source/svrtf/parrtf.cxx @@ -32,7 +32,6 @@ #include <svtools/parrtf.hxx> const int MAX_STRING_LEN = 1024; -const int MAX_TOKEN_LEN = 128; #define RTF_ISDIGIT( c ) rtl::isAsciiDigit(c) #define RTF_ISALPHA( c ) rtl::isAsciiAlpha(c) @@ -101,12 +100,10 @@ int SvRTFParser::GetNextToken_() { aToken = "\\"; { - OUStringBuffer aStrBuffer( MAX_TOKEN_LEN ); do { - aStrBuffer.appendUtf32(nNextCh); + aToken.appendUtf32(nNextCh); nNextCh = GetNextChar(); } while( RTF_ISALPHA( nNextCh ) ); - aToken.append( aStrBuffer ); } // minus before numeric parameters @@ -305,9 +302,9 @@ sal_Unicode SvRTFParser::GetHexValue() void SvRTFParser::ScanText() { const sal_Unicode cBreak = 0; - OUStringBuffer aStrBuffer; + const sal_uInt32 nStartLength = aToken.getLength(); bool bContinue = true; - while( bContinue && IsParserWorking() && aStrBuffer.getLength() < MAX_STRING_LEN) + while( bContinue && IsParserWorking() && aToken.getLength() - nStartLength < MAX_STRING_LEN) { bool bNextCh = true; switch( nNextCh ) @@ -345,8 +342,8 @@ void SvRTFParser::ScanText() if (next>0xFF) // fix for #i43933# and #i35653# { if (!aByteString.isEmpty()) - aStrBuffer.append( OStringToOUString(aByteString.makeStringAndClear(), GetSrcEncoding()) ); - aStrBuffer.append(static_cast<sal_Unicode>(next)); + aToken.append( OStringToOUString(aByteString.makeStringAndClear(), GetSrcEncoding()) ); + aToken.append(static_cast<sal_Unicode>(next)); continue; } @@ -386,23 +383,23 @@ void SvRTFParser::ScanText() bNextCh = false; if (!aByteString.isEmpty()) - aStrBuffer.append( OStringToOUString(aByteString.makeStringAndClear(), GetSrcEncoding()) ); + aToken.append( OStringToOUString(aByteString.makeStringAndClear(), GetSrcEncoding()) ); } break; case '\\': case '}': case '{': case '+': // I found in a RTF file - aStrBuffer.append(sal_Unicode(nNextCh)); + aToken.append(sal_Unicode(nNextCh)); break; case '~': // nonbreaking space - aStrBuffer.append(u'\x00A0'); + aToken.append(u'\x00A0'); break; case '-': // optional hyphen - aStrBuffer.append(u'\x00AD'); + aToken.append(u'\x00AD'); break; case '_': // nonbreaking hyphen - aStrBuffer.append(u'\x2011'); + aToken.append(u'\x2011'); break; case 'u': @@ -420,7 +417,7 @@ void SvRTFParser::ScanText() int nToken = GetNextToken_(); DBG_ASSERT( RTF_U == nToken, "still not a UNI-Code character" ); // don't convert symbol chars - aStrBuffer.append(static_cast< sal_Unicode >(nTokenValue)); + aToken.append(static_cast< sal_Unicode >(nTokenValue)); // overread the next n "RTF" characters. This // can be also \{, \}, \'88 @@ -491,24 +488,20 @@ void SvRTFParser::ScanText() break; default: - if( nNextCh == cBreak || aStrBuffer.getLength() >= MAX_STRING_LEN) + if( nNextCh == cBreak || aToken.getLength() - nStartLength >= MAX_STRING_LEN) bContinue = false; else { do { // all other characters end up in the text - aStrBuffer.appendUtf32(nNextCh); + aToken.appendUtf32(nNextCh); if (sal_Unicode(EOF) == (nNextCh = GetNextChar())) - { - if (!aStrBuffer.isEmpty()) - aToken.append( aStrBuffer ); return; - } } while ( (RTF_ISALPHA(nNextCh) || RTF_ISDIGIT(nNextCh)) && - (aStrBuffer.getLength() < MAX_STRING_LEN) + (aToken.getLength() - nStartLength < MAX_STRING_LEN) ); bNextCh = false; } @@ -517,9 +510,6 @@ void SvRTFParser::ScanText() if( bContinue && bNextCh ) nNextCh = GetNextChar(); } - - if (!aStrBuffer.isEmpty()) - aToken.append( aStrBuffer ); } |