configmgr/source/access.hxx | 9 +- configmgr/source/components.hxx | 3 configmgr/source/config_map.hxx | 35 ++++++++ configmgr/source/data.hxx | 4 configmgr/source/nodemap.hxx | 4 sw/inc/docstyle.hxx | 26 +++--- sw/source/uibase/app/docstyle.cxx | 60 +++++++------- writerfilter/source/ooxml/OOXMLFactory.cxx | 74 +++++++++--------- writerfilter/source/ooxml/OOXMLFastContextHandler.cxx | 2 writerfilter/source/ooxml/OOXMLPropertySetImpl.cxx | 37 ++++----- writerfilter/source/ooxml/OOXMLPropertySetImpl.hxx | 7 - 11 files changed, 150 insertions(+), 111 deletions(-)
New commits: commit 4771c8836a3e4d5e8ac25a7212293a13fb1e73ba Author: Michael Meeks <michael.me...@collabora.com> Date: Sat Jun 28 22:59:33 2014 +0100 writerfilter: use XFastAttributes more efficiently. Don't duplicate UTF8 as UCS2 before converting to integers. Don't double convert every attribute, and allocate it twice. Change-Id: Ibb15d703f011865dac8eb72f18408a5d62b60d96 diff --git a/writerfilter/source/ooxml/OOXMLFactory.cxx b/writerfilter/source/ooxml/OOXMLFactory.cxx index 597631b..c45b4f5 100644 --- a/writerfilter/source/ooxml/OOXMLFactory.cxx +++ b/writerfilter/source/ooxml/OOXMLFactory.cxx @@ -21,6 +21,7 @@ #include <rtl/instance.hxx> #include <osl/mutex.hxx> +#include <sax/fastattribs.hxx> #include "OOXMLFactory.hxx" #include "OOXMLFastHelper.hxx" @@ -131,59 +132,61 @@ void OOXMLFactory::attributes(OOXMLFastContextHandler * pHandler, AttributeToResourceMap::const_iterator aIt; AttributeToResourceMap::const_iterator aEndIt = pMap->end(); + assert( dynamic_cast< sax_fastparser::FastAttributeList *>( Attribs.get() ) != NULL ); + sax_fastparser::FastAttributeList *pAttribs; + pAttribs = static_cast< sax_fastparser::FastAttributeList *>( Attribs.get() ); + for (aIt = pMap->begin(); aIt != aEndIt; ++aIt) { - Id nId = (*pTokenToIdMap)[aIt->first]; - if (Attribs->hasAttribute(aIt->first)) + sal_Int32 nToken = aIt->first; + if (pAttribs->hasAttribute(nToken)) { + Id nId = (*pTokenToIdMap)[nToken]; + switch (aIt->second.m_nResource) { case RT_Boolean: { - OUString aValue(Attribs->getValue(aIt->first)); - OOXMLFastHelper<OOXMLBooleanValue>::newProperty(pHandler, nId, aValue); - - OOXMLValue::Pointer_t pValue(new OOXMLBooleanValue(aValue)); - pFactory->attributeAction(pHandler, aIt->first, pValue); + const char *pValue = ""; + pAttribs->getAsChar(nToken, pValue); + OOXMLValue::Pointer_t xValue(new OOXMLBooleanValue(pValue)); + pHandler->newProperty(nId, xValue); + pFactory->attributeAction(pHandler, nToken, xValue); } break; case RT_String: { - OUString aValue(Attribs->getValue(aIt->first)); - OOXMLFastHelper<OOXMLStringValue>::newProperty - (pHandler, nId, aValue); - - OOXMLValue::Pointer_t pValue(new OOXMLStringValue(aValue)); - pFactory->attributeAction(pHandler, aIt->first, pValue); + OUString aValue(pAttribs->getValue(nToken)); + OOXMLValue::Pointer_t xValue(new OOXMLStringValue(aValue)); + pHandler->newProperty(nId, xValue); + pFactory->attributeAction(pHandler, nToken, xValue); } break; case RT_Integer: { - OUString aValue(Attribs->getValue(aIt->first)); - OOXMLFastHelper<OOXMLIntegerValue>::newProperty - (pHandler, nId, aValue); - - OOXMLValue::Pointer_t pValue(new OOXMLIntegerValue(aValue)); - pFactory->attributeAction(pHandler, aIt->first, pValue); + sal_Int32 nValue; + pAttribs->getAsInteger(nToken,nValue); + OOXMLValue::Pointer_t xValue(new OOXMLIntegerValue(nValue)); + pHandler->newProperty(nId, xValue); + pFactory->attributeAction(pHandler, nToken, xValue); } break; case RT_Hex: { - OUString aValue(Attribs->getValue(aIt->first)); - OOXMLFastHelper<OOXMLHexValue>::newProperty - (pHandler, nId, aValue); - - OOXMLValue::Pointer_t pValue(new OOXMLHexValue(aValue)); - pFactory->attributeAction(pHandler, aIt->first, pValue); + const char *pValue = ""; + pAttribs->getAsChar(nToken, pValue); + OOXMLValue::Pointer_t xValue(new OOXMLHexValue(pValue)); + pHandler->newProperty(nId, xValue); + pFactory->attributeAction(pHandler, nToken, xValue); } break; case RT_UniversalMeasure: { - OUString aValue(Attribs->getValue(aIt->first)); - OOXMLFastHelper<OOXMLUniversalMeasureValue>::newProperty(pHandler, nId, aValue); - - OOXMLValue::Pointer_t pValue(new OOXMLUniversalMeasureValue(aValue)); - pFactory->attributeAction(pHandler, aIt->first, pValue); + const char *pValue = ""; + pAttribs->getAsChar(nToken, pValue); + OOXMLValue::Pointer_t xValue(new OOXMLUniversalMeasureValue(pValue)); + pHandler->newProperty(nId, xValue); + pFactory->attributeAction(pHandler, nToken, xValue); } break; case RT_List: @@ -193,14 +196,11 @@ void OOXMLFactory::attributes(OOXMLFastContextHandler * pHandler, if (pListValueMap.get() != NULL) { - OUString aValue(Attribs->getValue(aIt->first)); + OUString aValue(Attribs->getValue(nToken)); sal_uInt32 nValue = (*pListValueMap)[aValue]; - - OOXMLFastHelper<OOXMLIntegerValue>::newProperty - (pHandler, nId, nValue); - - OOXMLValue::Pointer_t pValue(new OOXMLIntegerValue(nValue)); - pFactory->attributeAction(pHandler, aIt->first, pValue); + OOXMLValue::Pointer_t xValue(new OOXMLIntegerValue(nValue)); + pHandler->newProperty(nId, xValue); + pFactory->attributeAction(pHandler, nToken, xValue); } } break; diff --git a/writerfilter/source/ooxml/OOXMLFastContextHandler.cxx b/writerfilter/source/ooxml/OOXMLFastContextHandler.cxx index 4214380..f5b7c47 100644 --- a/writerfilter/source/ooxml/OOXMLFastContextHandler.cxx +++ b/writerfilter/source/ooxml/OOXMLFastContextHandler.cxx @@ -1311,7 +1311,7 @@ void OOXMLFastContextHandlerValue::setDefaultHexValue() { if (mpValue.get() == NULL) { - OOXMLValue::Pointer_t pValue(new OOXMLHexValue(0)); + OOXMLValue::Pointer_t pValue(new OOXMLHexValue(sal_uInt32(0))); setValue(pValue); } } diff --git a/writerfilter/source/ooxml/OOXMLPropertySetImpl.cxx b/writerfilter/source/ooxml/OOXMLPropertySetImpl.cxx index c45a0e0..2903554 100644 --- a/writerfilter/source/ooxml/OOXMLPropertySetImpl.cxx +++ b/writerfilter/source/ooxml/OOXMLPropertySetImpl.cxx @@ -269,14 +269,14 @@ OOXMLBooleanValue::OOXMLBooleanValue(bool bValue) { } -OOXMLBooleanValue::OOXMLBooleanValue(const OUString & rValue) +OOXMLBooleanValue::OOXMLBooleanValue(const char *pValue) : mbValue(false) { - mbValue = (rValue == "true" - || rValue == "True" - || rValue == "1" - || rValue == "on" - || rValue == "On"); + mbValue = !strcmp(pValue, "true") + || !strcmp(pValue, "True") + || !strcmp(pValue, "1") + || !strcmp(pValue, "on") + || !strcmp(pValue, "On"); } OOXMLBooleanValue::~OOXMLBooleanValue() @@ -574,12 +574,6 @@ OOXMLIntegerValue::OOXMLIntegerValue(sal_Int32 nValue) { } -OOXMLIntegerValue::OOXMLIntegerValue(const OUString & rValue) -: mnValue(0) -{ - mnValue = rValue.toInt32(); -} - OOXMLIntegerValue::~OOXMLIntegerValue() { } @@ -620,9 +614,9 @@ OOXMLHexValue::OOXMLHexValue(sal_uInt32 nValue) { } -OOXMLHexValue::OOXMLHexValue(const OUString & rValue) +OOXMLHexValue::OOXMLHexValue(const char * pValue) { - mnValue = rValue.toUInt32(16); + mnValue = rtl_str_toUInt32(pValue, 16); } OOXMLHexValue::~OOXMLHexValue() @@ -651,12 +645,17 @@ string OOXMLHexValue::toString() const // OOXMLUniversalMeasureValue -OOXMLUniversalMeasureValue::OOXMLUniversalMeasureValue(const OUString& rValue) +OOXMLUniversalMeasureValue::OOXMLUniversalMeasureValue(const char * pValue) { - if (rValue.endsWith("pt")) - mnValue = rValue.copy(0, rValue.getLength() - 2).toInt32() * 20; - else - mnValue = rValue.toInt32(); + mnValue = rtl_str_toUInt32(pValue, 10); // will ignore the trailing 'pt' + + int nLen = strlen(pValue); + if (nLen > 2 && + pValue[nLen-2] == 'p' && + pValue[nLen-1] == 't') + { + mnValue = mnValue * 20; + } } OOXMLUniversalMeasureValue::~OOXMLUniversalMeasureValue() diff --git a/writerfilter/source/ooxml/OOXMLPropertySetImpl.hxx b/writerfilter/source/ooxml/OOXMLPropertySetImpl.hxx index a26f4fd..f2f3f54 100644 --- a/writerfilter/source/ooxml/OOXMLPropertySetImpl.hxx +++ b/writerfilter/source/ooxml/OOXMLPropertySetImpl.hxx @@ -108,7 +108,7 @@ protected: bool mbValue; public: explicit OOXMLBooleanValue(bool bValue); - explicit OOXMLBooleanValue(const OUString & rValue); + explicit OOXMLBooleanValue(const char *pValue); virtual ~OOXMLBooleanValue(); virtual int getInt() const SAL_OVERRIDE; @@ -207,7 +207,6 @@ protected: sal_Int32 mnValue; public: explicit OOXMLIntegerValue(sal_Int32 nValue); - explicit OOXMLIntegerValue(const OUString & rValue); virtual ~OOXMLIntegerValue(); virtual int getInt() const SAL_OVERRIDE; @@ -224,7 +223,7 @@ protected: sal_uInt32 mnValue; public: explicit OOXMLHexValue(sal_uInt32 nValue); - explicit OOXMLHexValue(const OUString & rValue); + explicit OOXMLHexValue(const char * pValue); virtual ~OOXMLHexValue(); virtual int getInt() const SAL_OVERRIDE; @@ -240,7 +239,7 @@ class OOXMLUniversalMeasureValue : public OOXMLValue protected: sal_uInt32 mnValue; public: - explicit OOXMLUniversalMeasureValue(const OUString& rValue); + explicit OOXMLUniversalMeasureValue(const char * pValue); virtual ~OOXMLUniversalMeasureValue(); virtual int getInt() const SAL_OVERRIDE; commit 5ca0cd55a19c522f1479737d7164947ae1ca4a6b Author: Michael Meeks <michael.me...@collabora.com> Date: Sat Jun 28 21:08:57 2014 +0100 sw: better encapsulate StyleSheet iterator's list. Change-Id: I4fc06c739009a4754282854c4a0fce633213e50f diff --git a/sw/inc/docstyle.hxx b/sw/inc/docstyle.hxx index 957be85..63a30e0 100644 --- a/sw/inc/docstyle.hxx +++ b/sw/inc/docstyle.hxx @@ -36,15 +36,6 @@ class SwTxtFmtColl; class SwFrmFmt; class SwNumRule; -// Local helper class. -class SwPoolFmtList : public std::vector<OUString> -{ -public: - SwPoolFmtList() {} - void Append( char cChar, const OUString& rStr ); - void Erase(); -}; - // Temporary StyleSheet. class SW_DLLPUBLIC SwDocStyleSheet : public SfxStyleSheetBase { @@ -146,10 +137,25 @@ public: // Iterator for Pool. class SwStyleSheetIterator : public SfxStyleSheetIterator, public SfxListener { + // Local helper class. + class SwPoolFmtList + { + std::vector<OUString> maImpl; + public: + SwPoolFmtList() {} + void Append( char cChar, const OUString& rStr ); + void Erase() { maImpl.clear(); } + size_t size() { return maImpl.size(); } + bool empty() { return maImpl.empty(); } + sal_uInt32 FindName(SfxStyleFamily eFam, const OUString &rName); + void RemoveName(SfxStyleFamily eFam, const OUString &rName); + const OUString &operator[](sal_uInt32 nIdx) { return maImpl[ nIdx ]; } + }; + rtl::Reference< SwDocStyleSheet > mxIterSheet; rtl::Reference< SwDocStyleSheet > mxStyleSheet; SwPoolFmtList aLst; - sal_uInt16 nLastPos; + sal_uInt32 nLastPos; bool bFirstCalled; void AppendStyleList(const ::std::vector<OUString>& rLst, diff --git a/sw/source/uibase/app/docstyle.cxx b/sw/source/uibase/app/docstyle.cxx index 1ca2960..fb5845e 100644 --- a/sw/source/uibase/app/docstyle.cxx +++ b/sw/source/uibase/app/docstyle.cxx @@ -288,10 +288,10 @@ static const SwNumRule* lcl_FindNumRule( SwDoc& rDoc, return pRule; } -static sal_uInt16 lcl_FindName(const SwPoolFmtList& rLst, SfxStyleFamily eFam, - const OUString& rName) +sal_uInt32 SwStyleSheetIterator::SwPoolFmtList::FindName(SfxStyleFamily eFam, + const OUString &rName) { - if(!rLst.empty()) + if(!maImpl.empty()) { sal_Unicode cStyle(0); switch( eFam ) @@ -316,27 +316,32 @@ static sal_uInt16 lcl_FindName(const SwPoolFmtList& rLst, SfxStyleFamily eFam, break; } const OUString sSrch = OUString(cStyle) + rName; - for(size_t i = 0; i < rLst.size(); ++i) - if(rLst[i] == sSrch) + for(size_t i = 0; i < maImpl.size(); ++i) + if(maImpl[i] == sSrch) return i; } - return USHRT_MAX; + return SAL_MAX_UINT32; +} + +void SwStyleSheetIterator::SwPoolFmtList::RemoveName(SfxStyleFamily eFam, + const OUString &rName) +{ + sal_uInt32 nTmpPos = FindName( eFam, rName ); + if( nTmpPos < maImpl.size() ) + maImpl.erase(maImpl.begin() + nTmpPos); } // Add Strings to the list of templates -void SwPoolFmtList::Append( char cChar, const OUString& rStr ) +void SwStyleSheetIterator::SwPoolFmtList::Append( char cChar, const OUString& rStr ) { const OUString aStr = OUString(cChar) + rStr; - for(std::vector<OUString>::const_iterator i = begin(); i != end(); ++i) + for(std::vector<OUString>::const_iterator i = maImpl.begin(); + i != maImpl.end(); ++i) + { if(*i == aStr) return; - push_back(aStr); -} - -// Erase the list completely -void SwPoolFmtList::Erase() -{ - clear(); + } + maImpl.push_back(aStr); } // UI-sided implementation of StyleSheets @@ -2481,7 +2486,7 @@ sal_uInt16 SwStyleSheetIterator::Count() return aLst.size(); } -SfxStyleSheetBase* SwStyleSheetIterator::operator[]( sal_uInt16 nIdx ) +SfxStyleSheetBase* SwStyleSheetIterator::operator[]( sal_uInt16 nIdx ) { // found if( !bFirstCalled ) @@ -2840,17 +2845,17 @@ SfxStyleSheetBase* SwStyleSheetIterator::First() if(!aLst.empty()) { - nLastPos = USHRT_MAX; + nLastPos = SAL_MAX_UINT32; return Next(); } return 0; } -SfxStyleSheetBase* SwStyleSheetIterator::Next() +SfxStyleSheetBase* SwStyleSheetIterator::Next() { assert(bFirstCalled); ++nLastPos; - if(!aLst.empty() && nLastPos < aLst.size()) + if(nLastPos < aLst.size()) { mxIterSheet->PresetNameAndFamily(aLst[nLastPos]); mxIterSheet->SetPhysical( false ); @@ -2865,14 +2870,14 @@ SfxStyleSheetBase* SwStyleSheetIterator::Next() return 0; } -SfxStyleSheetBase* SwStyleSheetIterator::Find(const OUString& rName) +SfxStyleSheetBase* SwStyleSheetIterator::Find(const OUString& rName) { // searching if( !bFirstCalled ) First(); - nLastPos = lcl_FindName( aLst, nSearchFamily, rName ); - if( USHRT_MAX != nLastPos ) + nLastPos = aLst.FindName( nSearchFamily, rName ); + if( SAL_MAX_UINT32 != nLastPos ) { // found mxStyleSheet->PresetNameAndFamily(aLst[nLastPos]); @@ -2948,7 +2953,7 @@ void SwDocStyleSheetPool::InvalidateIterator() dynamic_cast<SwStyleSheetIterator&>(GetIterator_Impl()).InvalidateIterator(); } -void SwStyleSheetIterator::InvalidateIterator() +void SwStyleSheetIterator::InvalidateIterator() { // potentially we could send an SfxHint to Notify but currently it's // iterating over the vector anyway so would still be slow - why does @@ -2958,7 +2963,7 @@ void SwStyleSheetIterator::InvalidateIterator() aLst.Erase(); } -void SwStyleSheetIterator::Notify( SfxBroadcaster&, const SfxHint& rHint ) +void SwStyleSheetIterator::Notify( SfxBroadcaster&, const SfxHint& rHint ) { // search and remove from View-List!! if( rHint.ISA( SfxStyleSheetHint ) && @@ -2967,12 +2972,7 @@ void SwStyleSheetIterator::Notify( SfxBroadcaster&, const SfxHint& rHint ) SfxStyleSheetBase* pStyle = ((SfxStyleSheetHint&)rHint).GetStyleSheet(); if (pStyle) - { - sal_uInt16 nTmpPos = lcl_FindName( aLst, pStyle->GetFamily(), - pStyle->GetName() ); - if( nTmpPos < aLst.size() ) - aLst.erase(aLst.begin() + nTmpPos); - } + aLst.RemoveName(pStyle->GetFamily(), pStyle->GetName()); } } commit bfb978334cea775b8ae5c40ceea050ea0660d80a Author: Michael Meeks <michael.me...@collabora.com> Date: Sat Jun 28 20:10:33 2014 +0100 configmgr: faster / simpler compare for keys. A surprising amount of time is/was spent comparing keys in the std::map red/black tree traversing nodes. Since we don't need the data truly sorted, instead sort in length buckets. Kills 90k rtl_ustring_compare_withLength calls on startup, around 0.9% of headless start. Change-Id: Ib23aff151ad50d56bbf2ba3e28882cc81898d9ec diff --git a/configmgr/source/access.hxx b/configmgr/source/access.hxx index de35555..807f2a2 100644 --- a/configmgr/source/access.hxx +++ b/configmgr/source/access.hxx @@ -25,6 +25,7 @@ #include <map> #include <set> #include <vector> +#include "config_map.hxx" #include <boost/noncopyable.hpp> #include <boost/shared_ptr.hpp> @@ -486,7 +487,7 @@ private: bool theDirectlyModified); }; - typedef std::map< OUString, ModifiedChild > ModifiedChildren; + typedef config_map< ModifiedChild > ModifiedChildren; rtl::Reference< ChildAccess > getModifiedChild( ModifiedChildren::iterator const & childIterator); @@ -515,7 +516,7 @@ private: rtl::Reference< Access > getNotificationRoot(); - typedef std::map< OUString, ChildAccess * > WeakChildMap; + typedef config_map< ChildAccess * > WeakChildMap; typedef std::multiset< @@ -535,7 +536,7 @@ private: com::sun::star::beans::XPropertyChangeListener > > PropertyChangeListenersElement; - typedef std::map< OUString, PropertyChangeListenersElement > + typedef config_map< PropertyChangeListenersElement > PropertyChangeListeners; typedef @@ -544,7 +545,7 @@ private: com::sun::star::beans::XVetoableChangeListener > > VetoableChangeListenersElement; - typedef std::map< OUString, VetoableChangeListenersElement > + typedef config_map< VetoableChangeListenersElement > VetoableChangeListeners; typedef diff --git a/configmgr/source/components.hxx b/configmgr/source/components.hxx index 4edaeec..48c1f7a 100644 --- a/configmgr/source/components.hxx +++ b/configmgr/source/components.hxx @@ -148,8 +148,7 @@ private: typedef std::set< RootAccess * > WeakRootSet; typedef - std::map< - OUString, + config_map< com::sun::star::uno::Reference< com::sun::star::beans::XPropertySet > > ExternalServices; diff --git a/configmgr/source/config_map.hxx b/configmgr/source/config_map.hxx new file mode 100644 index 0000000..0e9f614 --- /dev/null +++ b/configmgr/source/config_map.hxx @@ -0,0 +1,35 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ +#ifndef CONFIG_MAP_HXX +#define CONFIG_MAP_HXX + +#include <map> +#include <rtl/ustring.hxx> + +// The realisation here is that while a map is a reasonably compact +// representation, there is often no need to have it completely +// sorted, so we can use a fast in-line length comparison as the +// initial compare, rather than sorting of sub string contents. + +struct LengthContentsCompare +{ + inline bool operator()( const OUString &a, const OUString &b ) const + { + if (a.getLength() == b.getLength()) + return a < b; + else + return a.getLength() < b.getLength(); + } +}; + +template< class T > struct config_map : public std::map< OUString, T, LengthContentsCompare > { }; + +#endif // CONFIG_MAP_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/configmgr/source/data.hxx b/configmgr/source/data.hxx index 2e564d9..17a0e1d 100644 --- a/configmgr/source/data.hxx +++ b/configmgr/source/data.hxx @@ -23,7 +23,7 @@ #include <sal/config.h> #include <climits> -#include <map> +#include "config_map.hxx" #include <vector> #include <boost/noncopyable.hpp> @@ -86,7 +86,7 @@ struct Data: private boost::noncopyable { OUString const & url); private: - typedef std::map< OUString, rtl::Reference< ExtensionXcu > > + typedef config_map< rtl::Reference< ExtensionXcu > > ExtensionXcuAdditions; rtl::Reference< Node > root_; diff --git a/configmgr/source/nodemap.hxx b/configmgr/source/nodemap.hxx index 9742054..068a471 100644 --- a/configmgr/source/nodemap.hxx +++ b/configmgr/source/nodemap.hxx @@ -21,13 +21,13 @@ #define INCLUDED_CONFIGMGR_SOURCE_NODEMAP_HXX #include <sal/config.h> -#include <map> +#include "config_map.hxx" #include <rtl/ref.hxx> #include <node.hxx> namespace configmgr { -typedef std::map< OUString, rtl::Reference< Node > > NodeMapImpl; +typedef config_map< rtl::Reference< Node > > NodeMapImpl; class NodeMap { NodeMapImpl maImpl; _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits