diff options
author | Jan-Marek Glogowski <glogow@fbihome.de> | 2018-10-05 22:02:45 +0000 |
---|---|---|
committer | Jan-Marek Glogowski <glogow@fbihome.de> | 2018-10-06 02:25:40 +0200 |
commit | e7d5bad5ae083da12c3ec4a4a8bdc8b42447a242 (patch) | |
tree | 3dcb983f4b431a9e2c46236b96c2816859492251 | |
parent | 0f1ae0debdcb0d3e80651873b09ad23dfaa90123 (diff) |
lru_map: fix std::move insert
After the move the std::pair is invalid.
That caused invalid iterators on lookups - hard to debug...
Also adds an assertion to warn if size of map and list differ.
Change-Id: Ib987d47963d5e1009d64a96dcdd588a0bc27cd77
Reviewed-on: https://gerrit.libreoffice.org/61451
Tested-by: Jenkins
Reviewed-by: Jan-Marek Glogowski <glogow@fbihome.de>
-rw-r--r-- | include/o3tl/lru_map.hxx | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/include/o3tl/lru_map.hxx b/include/o3tl/lru_map.hxx index f2369e45030a..015120e31cb3 100644 --- a/include/o3tl/lru_map.hxx +++ b/include/o3tl/lru_map.hxx @@ -11,6 +11,7 @@ #ifndef INCLUDED_O3TL_LRU_MAP_HXX #define INCLUDED_O3TL_LRU_MAP_HXX +#include <cassert> #include <list> #include <unordered_map> @@ -74,7 +75,8 @@ public: // add to front of the list mLruList.push_front(rPair); // add the list position (iterator) to the map - mLruMap[rPair.first] = mLruList.begin(); + auto it = mLruList.begin(); + mLruMap[it->first] = it; checkLRU(); } else // already exists -> replace value @@ -95,7 +97,8 @@ public: // add to front of the list mLruList.push_front(std::move(rPair)); // add the list position (iterator) to the map - mLruMap[rPair.first] = mLruList.begin(); + auto it = mLruList.begin(); + mLruMap[it->first] = it; checkLRU(); } else // already exists -> replace value @@ -130,7 +133,8 @@ public: size_t size() const { - return mLruList.size(); + assert(mLruMap.size() == mLruList.size()); + return mLruMap.size(); } void clear() |