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
This commit is contained in:
Michael Meeks 2014-06-28 20:10:33 +01:00
parent 83d00917f2
commit bfb978334c
5 changed files with 45 additions and 10 deletions

View file

@ -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

View file

@ -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;

View file

@ -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: */

View file

@ -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_;

View file

@ -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;