From 6eaacd6d6263316a7f554ea1c93fa22525a0e88a Mon Sep 17 00:00:00 2001 From: Marius Kintel Date: Wed, 25 Jan 2012 00:02:06 +0100 Subject: Added note about reference usage being unsafe due to potential vector resize diff --git a/src/nodecache.h b/src/nodecache.h index 61afe3e..4acee2e 100644 --- a/src/nodecache.h +++ b/src/nodecache.h @@ -20,12 +20,17 @@ public: return !(*this)[node].empty(); } + /*! Returns a reference to the cached string copy. NB! don't rely on + * this reference to be valid for long - if the cache is resized + * internally, existing values are lost. */ const std::string & operator[](const AbstractNode &node) const { if (this->cache.size() > node.index()) return this->cache[node.index()]; else return this->nullvalue; } - /*! Returns a reference to the cached string copy */ + /*! Returns a reference to the cached string copy. NB! don't rely on + * this reference to be valid for long - if the cache is resized + * internally, existing values are lost. */ const std::string &insert(const class AbstractNode &node, const std::string & value) { if (this->cache.size() <= node.index()) this->cache.resize(node.index() + 1); return this->cache[node.index()] = value; -- cgit v0.10.1