diff options
author | Noel Grandin <noelgrandin@gmail.com> | 2019-10-17 20:33:50 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2019-11-03 17:11:32 +0100 |
commit | 48101a1a0d574db3db1f99c782bd67e885b232bb (patch) | |
tree | afd2f88944d73f43762b3a31df2ff81c8115ba9e /xmloff | |
parent | ab285c743afa1c8769581871d7b56374fd8c49f1 (diff) |
size some stringbuffer to prevent re-alloc
I started with 32 and kept doubling the size until the site
did not need re-alloc, but clamped it at 512.
Change-Id: I55fe36b31cd3d40f86e5729337a927cf920f2af6
Reviewed-on: https://gerrit.libreoffice.org/81960
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'xmloff')
-rw-r--r-- | xmloff/source/core/xmluconv.cxx | 12 | ||||
-rw-r--r-- | xmloff/source/style/xmlnume.cxx | 54 |
2 files changed, 35 insertions, 31 deletions
diff --git a/xmloff/source/core/xmluconv.cxx b/xmloff/source/core/xmluconv.cxx index dcfae65672f1..dfff05c31f7e 100644 --- a/xmloff/source/core/xmluconv.cxx +++ b/xmloff/source/core/xmluconv.cxx @@ -185,6 +185,16 @@ void SvXMLUnitConverter::convertMeasureToXML( OUStringBuffer& rString, m_pImpl->m_eXMLMeasureUnit ); } +/** convert measure to string */ +OUString SvXMLUnitConverter::convertMeasureToXML( sal_Int32 nMeasure ) const +{ + OUStringBuffer s; + ::sax::Converter::convertMeasure( s, nMeasure, + m_pImpl->m_eCoreMeasureUnit, + m_pImpl->m_eXMLMeasureUnit ); + return s.makeStringAndClear(); +} + /** convert string to enum using given enum map, if the enum is not found in the map, this method will return false */ @@ -733,7 +743,7 @@ OUString SvXMLUnitConverter::encodeStyleName( *pEncoded = false; sal_Int32 nLen = rName.getLength(); - OUStringBuffer aBuffer( nLen ); + OUStringBuffer aBuffer( nLen*2 ); for( sal_Int32 i = 0; i < nLen; i++ ) { diff --git a/xmloff/source/style/xmlnume.cxx b/xmloff/source/style/xmlnume.cxx index e9908c8991a5..0f5a45dc40da 100644 --- a/xmloff/source/style/xmlnume.cxx +++ b/xmloff/source/style/xmlnume.cxx @@ -344,31 +344,26 @@ void SvxXMLNumRuleExport::exportLevelStyle( sal_Int32 nLevel, SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_TEXT, eElem, true, true ); - OUStringBuffer sBuffer; if ( ePosAndSpaceMode == PositionAndSpaceMode::LABEL_WIDTH_AND_POSITION ) { nSpaceBefore += nMinLabelWidth; nMinLabelWidth = -nMinLabelWidth; if( nSpaceBefore != 0 ) { - GetExport().GetMM100UnitConverter().convertMeasureToXML( - sBuffer, nSpaceBefore ); - GetExport().AddAttribute( XML_NAMESPACE_TEXT, XML_SPACE_BEFORE, - sBuffer.makeStringAndClear() ); + OUString sAttr = GetExport().GetMM100UnitConverter().convertMeasureToXML( + nSpaceBefore ); + GetExport().AddAttribute( XML_NAMESPACE_TEXT, XML_SPACE_BEFORE, sAttr ); } if( nMinLabelWidth != 0 ) { - GetExport().GetMM100UnitConverter().convertMeasureToXML( - sBuffer, nMinLabelWidth ); - GetExport().AddAttribute( XML_NAMESPACE_TEXT, XML_MIN_LABEL_WIDTH, - sBuffer.makeStringAndClear() ); + OUString s = GetExport().GetMM100UnitConverter().convertMeasureToXML( nMinLabelWidth ); + GetExport().AddAttribute( XML_NAMESPACE_TEXT, XML_MIN_LABEL_WIDTH, s); } if( nMinLabelDist > 0 ) { - GetExport().GetMM100UnitConverter().convertMeasureToXML( - sBuffer, nMinLabelDist ); - GetExport().AddAttribute( XML_NAMESPACE_TEXT, XML_MIN_LABEL_DISTANCE, - sBuffer.makeStringAndClear() ); + OUString sAttr = GetExport().GetMM100UnitConverter().convertMeasureToXML( + nMinLabelDist ); + GetExport().AddAttribute( XML_NAMESPACE_TEXT, XML_MIN_LABEL_DISTANCE, sAttr); } } /* Check, if properties for position-and-space-mode LABEL_ALIGNMENT @@ -443,18 +438,16 @@ void SvxXMLNumRuleExport::exportLevelStyle( sal_Int32 nLevel, if( nImageWidth > 0 ) { - GetExport().GetMM100UnitConverter().convertMeasureToXML( - sBuffer, nImageWidth ); - GetExport().AddAttribute( XML_NAMESPACE_FO, XML_WIDTH, - sBuffer.makeStringAndClear() ); + OUString sAttr = GetExport().GetMM100UnitConverter().convertMeasureToXML( + nImageWidth ); + GetExport().AddAttribute( XML_NAMESPACE_FO, XML_WIDTH, sAttr ); } if( nImageHeight > 0 ) { - GetExport().GetMM100UnitConverter().convertMeasureToXML( - sBuffer, nImageHeight ); - GetExport().AddAttribute( XML_NAMESPACE_FO, XML_HEIGHT, - sBuffer.makeStringAndClear() ); + OUString sAttr = GetExport().GetMM100UnitConverter().convertMeasureToXML( + nImageHeight ); + GetExport().AddAttribute( XML_NAMESPACE_FO, XML_HEIGHT, sAttr ); } } @@ -490,29 +483,29 @@ void SvxXMLNumRuleExport::exportLevelStyle( sal_Int32 nLevel, if ( eLabelFollowedBy == LabelFollow::LISTTAB && nListtabStopPosition > 0 ) { - GetExport().GetMM100UnitConverter().convertMeasureToXML( - sBuffer, nListtabStopPosition ); + OUString sAttr = GetExport().GetMM100UnitConverter().convertMeasureToXML( + nListtabStopPosition ); GetExport().AddAttribute( XML_NAMESPACE_TEXT, XML_LIST_TAB_STOP_POSITION, - sBuffer.makeStringAndClear() ); + sAttr ); } if ( nFirstLineIndent != 0 ) { - GetExport().GetMM100UnitConverter().convertMeasureToXML( - sBuffer, nFirstLineIndent ); + OUString sAttr = GetExport().GetMM100UnitConverter().convertMeasureToXML( + nFirstLineIndent ); GetExport().AddAttribute( XML_NAMESPACE_FO, XML_TEXT_INDENT, - sBuffer.makeStringAndClear() ); + sAttr ); } if ( nIndentAt != 0 ) { - GetExport().GetMM100UnitConverter().convertMeasureToXML( - sBuffer, nIndentAt ); + OUString sAttr = GetExport().GetMM100UnitConverter().convertMeasureToXML( + nIndentAt ); GetExport().AddAttribute( XML_NAMESPACE_FO, XML_MARGIN_LEFT, - sBuffer.makeStringAndClear() ); + sAttr ); } SvXMLElementExport aLabelAlignmentElement( GetExport(), XML_NAMESPACE_STYLE, @@ -582,6 +575,7 @@ void SvxXMLNumRuleExport::exportLevelStyle( sal_Int32 nLevel, } else { + OUStringBuffer sBuffer; ::sax::Converter::convertColor( sBuffer, nColor ); GetExport().AddAttribute( XML_NAMESPACE_FO, XML_COLOR, sBuffer.makeStringAndClear() ); |