From bfb978334cea775b8ae5c40ceea050ea0660d80a Mon Sep 17 00:00:00 2001 From: Michael Meeks Date: Sat, 28 Jun 2014 20:10:33 +0100 Subject: 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 --- 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 ++-- 5 files changed, 45 insertions(+), 10 deletions(-) create mode 100644 configmgr/source/config_map.hxx diff --git a/configmgr/source/access.hxx b/configmgr/source/access.hxx index de35555522dc..807f2a2a9724 100644 --- a/configmgr/source/access.hxx +++ b/configmgr/source/access.hxx @@ -25,6 +25,7 @@ #include #include #include +#include "config_map.hxx" #include #include @@ -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 4edaeec1eba6..48c1f7a73199 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 000000000000..0e9f614bb5cd --- /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 +#include + +// 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 2e564d953d1e..17a0e1dec879 100644 --- a/configmgr/source/data.hxx +++ b/configmgr/source/data.hxx @@ -23,7 +23,7 @@ #include #include -#include +#include "config_map.hxx" #include #include @@ -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 97420544568a..068a471c670f 100644 --- a/configmgr/source/nodemap.hxx +++ b/configmgr/source/nodemap.hxx @@ -21,13 +21,13 @@ #define INCLUDED_CONFIGMGR_SOURCE_NODEMAP_HXX #include -#include +#include "config_map.hxx" #include #include namespace configmgr { -typedef std::map< OUString, rtl::Reference< Node > > NodeMapImpl; +typedef config_map< rtl::Reference< Node > > NodeMapImpl; class NodeMap { NodeMapImpl maImpl; -- cgit v1.2.3