include/comphelper/stl_types.hxx | 14 +++++ xmloff/source/style/impastpl.cxx | 36 ++++++------- xmlscript/source/xmldlg_imexp/exp_share.hxx | 2 xmlscript/source/xmldlg_imexp/xmldlg_export.cxx | 64 ++++++++++++------------ 4 files changed, 65 insertions(+), 51 deletions(-)
New commits: commit a76ae1c3d1076cbcb58d3fc27723e4eefffac0a3 Author: Noel Grandin <noel.gran...@collabora.co.uk> AuthorDate: Thu May 27 13:21:16 2021 +0200 Commit: Noel Grandin <noel.gran...@collabora.co.uk> CommitDate: Thu May 27 14:58:28 2021 +0200 no need to allocate Style objects separately Change-Id: I88e4642a81b18c41216784332cc4a37a3bde9d95 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/116247 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk> diff --git a/xmlscript/source/xmldlg_imexp/exp_share.hxx b/xmlscript/source/xmldlg_imexp/exp_share.hxx index dc7da2477194..919950c79bef 100644 --- a/xmlscript/source/xmldlg_imexp/exp_share.hxx +++ b/xmlscript/source/xmldlg_imexp/exp_share.hxx @@ -73,7 +73,7 @@ struct Style }; class StyleBag { - ::std::vector< std::unique_ptr<Style> > _styles; + ::std::vector<Style> _styles; public: ~StyleBag() ; diff --git a/xmlscript/source/xmldlg_imexp/xmldlg_export.cxx b/xmlscript/source/xmldlg_imexp/xmldlg_export.cxx index 55ee293bc464..6a7af3fc3d85 100644 --- a/xmlscript/source/xmldlg_imexp/xmldlg_export.cxx +++ b/xmlscript/source/xmldlg_imexp/xmldlg_export.cxx @@ -1272,72 +1272,72 @@ OUString StyleBag::getStyleId( Style const & rStyle ) } // lookup existing style - for (auto const & pStyle : _styles) + for (auto & rExistingStyle : _styles) { short demanded_defaults = ~rStyle._set & rStyle._all; // test, if defaults are not set - if ((~pStyle->_set & demanded_defaults) == demanded_defaults && - (rStyle._set & (pStyle->_all & ~pStyle->_set)) == 0) + if ((~rExistingStyle._set & demanded_defaults) == demanded_defaults && + (rStyle._set & (rExistingStyle._all & ~rExistingStyle._set)) == 0) { - short bset = rStyle._set & pStyle->_set; + short bset = rStyle._set & rExistingStyle._set; if ((bset & 0x1) && - rStyle._backgroundColor != pStyle->_backgroundColor) + rStyle._backgroundColor != rExistingStyle._backgroundColor) continue; if ((bset & 0x2) && - rStyle._textColor != pStyle->_textColor) + rStyle._textColor != rExistingStyle._textColor) continue; if ((bset & 0x20) && - rStyle._textLineColor != pStyle->_textLineColor) + rStyle._textLineColor != rExistingStyle._textLineColor) continue; if ((bset & 0x10) && - rStyle._fillColor != pStyle->_fillColor) + rStyle._fillColor != rExistingStyle._fillColor) continue; if ((bset & 0x4) && - (rStyle._border != pStyle->_border || + (rStyle._border != rExistingStyle._border || (rStyle._border == BORDER_SIMPLE_COLOR && - rStyle._borderColor != pStyle->_borderColor))) + rStyle._borderColor != rExistingStyle._borderColor))) continue; if ((bset & 0x8) && - !equalFont( rStyle, *pStyle )) + !equalFont( rStyle, rExistingStyle )) continue; if ((bset & 0x40) && - rStyle._visualEffect != pStyle->_visualEffect) + rStyle._visualEffect != rExistingStyle._visualEffect) continue; // merge in - short bnset = rStyle._set & ~pStyle->_set; + short bnset = rStyle._set & ~rExistingStyle._set; if (bnset & 0x1) - pStyle->_backgroundColor = rStyle._backgroundColor; + rExistingStyle._backgroundColor = rStyle._backgroundColor; if (bnset & 0x2) - pStyle->_textColor = rStyle._textColor; + rExistingStyle._textColor = rStyle._textColor; if (bnset & 0x20) - pStyle->_textLineColor = rStyle._textLineColor; + rExistingStyle._textLineColor = rStyle._textLineColor; if (bnset & 0x10) - pStyle->_fillColor = rStyle._fillColor; + rExistingStyle._fillColor = rStyle._fillColor; if (bnset & 0x4) { - pStyle->_border = rStyle._border; - pStyle->_borderColor = rStyle._borderColor; + rExistingStyle._border = rStyle._border; + rExistingStyle._borderColor = rStyle._borderColor; } if (bnset & 0x8) { - pStyle->_descr = rStyle._descr; - pStyle->_fontRelief = rStyle._fontRelief; - pStyle->_fontEmphasisMark = rStyle._fontEmphasisMark; + rExistingStyle._descr = rStyle._descr; + rExistingStyle._fontRelief = rStyle._fontRelief; + rExistingStyle._fontEmphasisMark = rStyle._fontEmphasisMark; } if (bnset & 0x40) - pStyle->_visualEffect = rStyle._visualEffect; + rExistingStyle._visualEffect = rStyle._visualEffect; - pStyle->_all |= rStyle._all; - pStyle->_set |= rStyle._set; + rExistingStyle._all |= rStyle._all; + rExistingStyle._set |= rStyle._set; - return pStyle->_id; + return rExistingStyle._id; } } // no appr style found, append new - std::unique_ptr<Style> pStyle(new Style( rStyle )); - pStyle->_id = OUString::number( _styles.size() ); - _styles.push_back( std::move(pStyle) ); - return _styles.back()->_id; + Style aNewStyle( rStyle ); + aNewStyle._id = OUString::number( _styles.size() ); + _styles.push_back( aNewStyle ); + return _styles.back()._id; } StyleBag::~StyleBag() @@ -1353,9 +1353,9 @@ void StyleBag::dump( Reference< xml::sax::XExtendedDocumentHandler > const & xOu xOut->ignorableWhitespace( OUString() ); xOut->startElement( aStylesName, Reference< xml::sax::XAttributeList >() ); // export styles - for (auto const & _style : _styles) + for (auto & _style : _styles) { - Reference< xml::sax::XAttributeList > xAttr( _style->createElement() ); + Reference< xml::sax::XAttributeList > xAttr( _style.createElement() ); static_cast< ElementDescriptor * >( xAttr.get() )->dump( xOut ); } xOut->ignorableWhitespace( OUString() ); commit 2d0eea0a79df9bc54e075c90ee7d6134b03250c0 Author: Noel Grandin <noel.gran...@collabora.co.uk> AuthorDate: Thu May 27 13:37:45 2021 +0200 Commit: Noel Grandin <noel.gran...@collabora.co.uk> CommitDate: Thu May 27 14:58:12 2021 +0200 we can search std::set without allocating on the heap we just need to add some overloads to UniquePtrValueLess Change-Id: I91c395393a2de609c8f442de605d1dd2098dfae0 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/116248 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk> diff --git a/include/comphelper/stl_types.hxx b/include/comphelper/stl_types.hxx index 5e8a532a60b9..5693a83338f5 100644 --- a/include/comphelper/stl_types.hxx +++ b/include/comphelper/stl_types.hxx @@ -74,6 +74,20 @@ template<class T> struct UniquePtrValueLess assert(rhs.get()); return (*lhs) < (*rhs); } + // The following are so we can search in std::set without allocating a temporary entry on the heap + typedef bool is_transparent; + bool operator()(T const& lhs, + std::unique_ptr<T> const& rhs) const + { + assert(rhs.get()); + return lhs < (*rhs); + } + bool operator()(std::unique_ptr<T> const& lhs, + T const& rhs) const + { + assert(lhs.get()); + return (*lhs) < rhs; + } }; /// by-value implementation of std::foo<std::unique_ptr<T>>::operator== diff --git a/xmloff/source/style/impastpl.cxx b/xmloff/source/style/impastpl.cxx index 0a3e2e97595f..b965b7a5a8f8 100644 --- a/xmloff/source/style/impastpl.cxx +++ b/xmloff/source/style/impastpl.cxx @@ -367,8 +367,8 @@ void SvXMLAutoStylePoolP_Impl::AddFamily( } #if OSL_DEBUG_LEVEL > 0 - std::unique_ptr<XMLAutoStyleFamily> pTemp(new XMLAutoStyleFamily(nFamily)); - auto const iter = m_FamilySet.find(pTemp); + XMLAutoStyleFamily aTemp(nFamily); + auto const iter = m_FamilySet.find(aTemp); if (iter != m_FamilySet.end()) { // FIXME: do we really intend to replace the previous nFamily @@ -388,8 +388,8 @@ void SvXMLAutoStylePoolP_Impl::SetFamilyPropSetMapper( XmlStyleFamily nFamily, const rtl::Reference < SvXMLExportPropertyMapper > & rMapper ) { - std::unique_ptr<XMLAutoStyleFamily> pTemp(new XMLAutoStyleFamily(nFamily)); - auto const iter = m_FamilySet.find(pTemp); + XMLAutoStyleFamily aTemp(nFamily); + auto const iter = m_FamilySet.find(aTemp); if (iter != m_FamilySet.end()) (*iter)->mxMapper = rMapper; } @@ -397,8 +397,8 @@ void SvXMLAutoStylePoolP_Impl::SetFamilyPropSetMapper( // Adds a name to list void SvXMLAutoStylePoolP_Impl::RegisterName( XmlStyleFamily nFamily, const OUString& rName ) { - std::unique_ptr<XMLAutoStyleFamily> pTemp(new XMLAutoStyleFamily(nFamily)); - auto const iter = m_FamilySet.find(pTemp); + XMLAutoStyleFamily aTemp(nFamily); + auto const iter = m_FamilySet.find(aTemp); assert(iter != m_FamilySet.end()); // family must be known // SAL_DEBUG("SvXMLAutoStylePoolP_Impl::RegisterName: " << nFamily << ", '" << rName << "'"); (*iter)->maNameSet.insert(rName); @@ -407,8 +407,8 @@ void SvXMLAutoStylePoolP_Impl::RegisterName( XmlStyleFamily nFamily, const OUStr // Adds a name to list void SvXMLAutoStylePoolP_Impl::RegisterDefinedName( XmlStyleFamily nFamily, const OUString& rName ) { - std::unique_ptr<XMLAutoStyleFamily> pTemp(new XMLAutoStyleFamily(nFamily)); - auto const iter = m_FamilySet.find(pTemp); + XMLAutoStyleFamily aTemp(nFamily); + auto const iter = m_FamilySet.find(aTemp); assert(iter != m_FamilySet.end()); // family must be known (*iter)->maReservedNameSet.insert(rName); } @@ -455,8 +455,8 @@ bool SvXMLAutoStylePoolP_Impl::Add( OUString& rName, XmlStyleFamily nFamily, const OUString& rParentName, const ::std::vector< XMLPropertyState >& rProperties, bool bDontSeek ) { - std::unique_ptr<XMLAutoStyleFamily> pTemp(new XMLAutoStyleFamily(nFamily)); - auto const iter = m_FamilySet.find(pTemp); + XMLAutoStyleFamily aTemp(nFamily); + auto const iter = m_FamilySet.find(aTemp); assert(iter != m_FamilySet.end()); // family must be known XMLAutoStyleFamily &rFamily = **iter; @@ -481,8 +481,8 @@ bool SvXMLAutoStylePoolP_Impl::AddNamed( { // get family and parent the same way as in Add() - std::unique_ptr<XMLAutoStyleFamily> pTemp(new XMLAutoStyleFamily(nFamily)); - auto const iter = m_FamilySet.find(pTemp); + XMLAutoStyleFamily aTemp(nFamily); + auto const iter = m_FamilySet.find(aTemp); assert(iter != m_FamilySet.end()); // family must be known XMLAutoStyleFamily &rFamily = **iter; @@ -511,13 +511,13 @@ OUString SvXMLAutoStylePoolP_Impl::Find( XmlStyleFamily nFamily, { OUString sName; - std::unique_ptr<XMLAutoStyleFamily> pTemp(new XMLAutoStyleFamily(nFamily)); - auto const iter = m_FamilySet.find(pTemp); + XMLAutoStyleFamily aTemp(nFamily); + auto const iter = m_FamilySet.find(aTemp); assert(iter != m_FamilySet.end()); // family must be known XMLAutoStyleFamily const& rFamily = **iter; - std::unique_ptr<XMLAutoStylePoolParent> pTmp(new XMLAutoStylePoolParent(rParent)); - auto const it2 = rFamily.m_ParentSet.find(pTmp); + XMLAutoStylePoolParent aTmp(rParent); + auto const it2 = rFamily.m_ParentSet.find(aTmp); if (it2 != rFamily.m_ParentSet.end()) { sName = (*it2)->Find(rFamily, rProperties); @@ -579,8 +579,8 @@ void SvXMLAutoStylePoolP_Impl::exportXML( const SvXMLAutoStylePoolP *pAntiImpl) const { // Get list of parents for current family (nFamily) - std::unique_ptr<XMLAutoStyleFamily> pTemp(new XMLAutoStyleFamily(nFamily)); - auto const iter = m_FamilySet.find(pTemp); + XMLAutoStyleFamily aTemp(nFamily); + auto const iter = m_FamilySet.find(aTemp); assert(iter != m_FamilySet.end()); // family must be known const XMLAutoStyleFamily &rFamily = **iter; _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits