Kaydet (Commit) bfb97833 authored tarafından Michael Meeks's avatar Michael Meeks

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
üst 83d00917
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#include <map> #include <map>
#include <set> #include <set>
#include <vector> #include <vector>
#include "config_map.hxx"
#include <boost/noncopyable.hpp> #include <boost/noncopyable.hpp>
#include <boost/shared_ptr.hpp> #include <boost/shared_ptr.hpp>
...@@ -486,7 +487,7 @@ private: ...@@ -486,7 +487,7 @@ private:
bool theDirectlyModified); bool theDirectlyModified);
}; };
typedef std::map< OUString, ModifiedChild > ModifiedChildren; typedef config_map< ModifiedChild > ModifiedChildren;
rtl::Reference< ChildAccess > getModifiedChild( rtl::Reference< ChildAccess > getModifiedChild(
ModifiedChildren::iterator const & childIterator); ModifiedChildren::iterator const & childIterator);
...@@ -515,7 +516,7 @@ private: ...@@ -515,7 +516,7 @@ private:
rtl::Reference< Access > getNotificationRoot(); rtl::Reference< Access > getNotificationRoot();
typedef std::map< OUString, ChildAccess * > WeakChildMap; typedef config_map< ChildAccess * > WeakChildMap;
typedef typedef
std::multiset< std::multiset<
...@@ -535,7 +536,7 @@ private: ...@@ -535,7 +536,7 @@ private:
com::sun::star::beans::XPropertyChangeListener > > com::sun::star::beans::XPropertyChangeListener > >
PropertyChangeListenersElement; PropertyChangeListenersElement;
typedef std::map< OUString, PropertyChangeListenersElement > typedef config_map< PropertyChangeListenersElement >
PropertyChangeListeners; PropertyChangeListeners;
typedef typedef
...@@ -544,7 +545,7 @@ private: ...@@ -544,7 +545,7 @@ private:
com::sun::star::beans::XVetoableChangeListener > > com::sun::star::beans::XVetoableChangeListener > >
VetoableChangeListenersElement; VetoableChangeListenersElement;
typedef std::map< OUString, VetoableChangeListenersElement > typedef config_map< VetoableChangeListenersElement >
VetoableChangeListeners; VetoableChangeListeners;
typedef typedef
......
...@@ -148,8 +148,7 @@ private: ...@@ -148,8 +148,7 @@ private:
typedef std::set< RootAccess * > WeakRootSet; typedef std::set< RootAccess * > WeakRootSet;
typedef typedef
std::map< config_map<
OUString,
com::sun::star::uno::Reference< com::sun::star::uno::Reference<
com::sun::star::beans::XPropertySet > > com::sun::star::beans::XPropertySet > >
ExternalServices; ExternalServices;
......
/* -*- 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: */
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
#include <sal/config.h> #include <sal/config.h>
#include <climits> #include <climits>
#include <map> #include "config_map.hxx"
#include <vector> #include <vector>
#include <boost/noncopyable.hpp> #include <boost/noncopyable.hpp>
...@@ -86,7 +86,7 @@ struct Data: private boost::noncopyable { ...@@ -86,7 +86,7 @@ struct Data: private boost::noncopyable {
OUString const & url); OUString const & url);
private: private:
typedef std::map< OUString, rtl::Reference< ExtensionXcu > > typedef config_map< rtl::Reference< ExtensionXcu > >
ExtensionXcuAdditions; ExtensionXcuAdditions;
rtl::Reference< Node > root_; rtl::Reference< Node > root_;
......
...@@ -21,13 +21,13 @@ ...@@ -21,13 +21,13 @@
#define INCLUDED_CONFIGMGR_SOURCE_NODEMAP_HXX #define INCLUDED_CONFIGMGR_SOURCE_NODEMAP_HXX
#include <sal/config.h> #include <sal/config.h>
#include <map> #include "config_map.hxx"
#include <rtl/ref.hxx> #include <rtl/ref.hxx>
#include <node.hxx> #include <node.hxx>
namespace configmgr { namespace configmgr {
typedef std::map< OUString, rtl::Reference< Node > > NodeMapImpl; typedef config_map< rtl::Reference< Node > > NodeMapImpl;
class NodeMap class NodeMap
{ {
NodeMapImpl maImpl; NodeMapImpl maImpl;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment