summaryrefslogtreecommitdiff
path: root/src/nodecache.h
diff options
context:
space:
mode:
authorMarius Kintel <marius@kintel.net>2012-01-24 23:02:06 (GMT)
committerMarius Kintel <marius@kintel.net>2012-01-24 23:02:06 (GMT)
commit6eaacd6d6263316a7f554ea1c93fa22525a0e88a (patch)
tree02fbd3ad7d7b299b4d30620331f2d20a33f6839c /src/nodecache.h
parentd3fc11b7db2caf1c40e2effd0b62e47adba814fd (diff)
Added note about reference usage being unsafe due to potential vector resize
Diffstat (limited to 'src/nodecache.h')
-rw-r--r--src/nodecache.h7
1 files changed, 6 insertions, 1 deletions
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;
contact: Jan Huwald // Impressum