summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Meeks <michael.meeks@collabora.com>2014-06-26 15:12:04 +0100
committerMichael Meeks <michael.meeks@collabora.com>2014-06-28 14:37:23 +0100
commitf55ddffd7e81cc8f3314047a6aa62991e2d293b1 (patch)
treee135330ff31f80d4dd86414c44b9d1a530ed7c51
parent8bfdc161e6417a4f057f66af6c44299e22ad5a9c (diff)
configmgr: implement a single item cache for node lookup.
Saves 13.5m cycles on a headless start, 1.3%. Change-Id: I73f0dd8a523f84c765a217ee95aea9bcc3db1b5d
-rw-r--r--configmgr/source/nodemap.cxx10
-rw-r--r--configmgr/source/nodemap.hxx37
2 files changed, 29 insertions, 18 deletions
diff --git a/configmgr/source/nodemap.cxx b/configmgr/source/nodemap.cxx
index 3c7c79ae10c4..4d823ce73a6d 100644
--- a/configmgr/source/nodemap.cxx
+++ b/configmgr/source/nodemap.cxx
@@ -32,16 +32,20 @@ namespace configmgr {
void NodeMap::cloneInto(NodeMap * target) const
{
assert(target != 0 && target->empty());
- NodeMapImpl clone(aImpl);
+ NodeMapImpl clone(maImpl);
for (NodeMapImpl::iterator i(clone.begin()); i != clone.end(); ++i) {
i->second = i->second->clone(true);
}
- std::swap(clone, target->aImpl);
+ std::swap(clone, target->maImpl);
+ target->clearCache();
}
rtl::Reference< Node > NodeMap::findNode(int layer, OUString const & name) const
{
- const_iterator i(aImpl.find(name));
+ const_iterator i;
+ if (maCache == end() || maCache->first != name)
+ maCache = const_cast< NodeMap *>(this)->maImpl.find(name);
+ i = maCache;
return i == end() || i->second->getLayer() > layer
? rtl::Reference< Node >() : i->second;
}
diff --git a/configmgr/source/nodemap.hxx b/configmgr/source/nodemap.hxx
index 3745b862face..97420544568a 100644
--- a/configmgr/source/nodemap.hxx
+++ b/configmgr/source/nodemap.hxx
@@ -30,34 +30,41 @@ namespace configmgr {
typedef std::map< OUString, rtl::Reference< Node > > NodeMapImpl;
class NodeMap
{
- NodeMapImpl aImpl;
+ NodeMapImpl maImpl;
+
NodeMap(const NodeMap &rMap) :
- aImpl(rMap.aImpl) {}
+ maImpl(rMap.maImpl) { clearCache(); }
public:
typedef NodeMapImpl::iterator iterator;
typedef NodeMapImpl::const_iterator const_iterator;
typedef NodeMapImpl::value_type value_type;
- NodeMap() {}
+ NodeMap() { clearCache(); }
~NodeMap() {}
- void clear() { aImpl.clear(); }
- bool empty() const { return aImpl.empty(); }
- void erase(const iterator &it) { aImpl.erase(it); }
- void erase(const OUString &aStr) { aImpl.erase(aStr); }
- iterator find(const OUString &aStr) { return aImpl.find( aStr ); }
+ bool empty() const { return maImpl.empty(); }
+ iterator find(const OUString &aStr) { return maImpl.find( aStr ); }
+
+ const_iterator find(const OUString &aStr) const { return maImpl.find( aStr ); }
+ iterator begin() { return maImpl.begin(); }
+ const_iterator begin() const { return maImpl.begin(); }
- const_iterator find(const OUString &aStr) const { return aImpl.find( aStr ); }
- rtl::Reference<Node> &operator[](const OUString &aStr) { return aImpl[aStr]; }
- iterator begin() { return aImpl.begin(); }
- const_iterator begin() const { return aImpl.begin(); }
+ iterator end() { return maImpl.end(); }
+ const_iterator end() const { return maImpl.end(); }
- iterator end() { return aImpl.end(); }
- const_iterator end() const { return aImpl.end(); }
- std::pair<iterator,bool> insert(const value_type &vt) { return aImpl.insert(vt); }
+ rtl::Reference<Node> &operator[](const OUString &aStr) { return maImpl[aStr]; clearCache(); }
+ std::pair<iterator,bool> insert(const value_type &vt) { return maImpl.insert(vt); clearCache(); }
+ void clear() { maImpl.clear(); clearCache(); }
+ void erase(const iterator &it) { maImpl.erase(it); clearCache(); }
+ void erase(const OUString &aStr) { maImpl.erase(aStr); clearCache(); }
rtl::Reference< Node > findNode(int layer, OUString const & name) const;
void cloneInto(NodeMap * target) const;
+
+private:
+ // We get a large number of repeated identical lookups.
+ mutable const_iterator maCache;
+ void clearCache() { maCache = maImpl.end(); }
};
}