[Libreoffice-commits] core.git: include/o3tl
Libreoffice Gerrit user
logerrit at kemper.freedesktop.org
Sat Oct 6 00:26:06 UTC 2018
include/o3tl/lru_map.hxx | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
New commits:
commit e7d5bad5ae083da12c3ec4a4a8bdc8b42447a242
Author: Jan-Marek Glogowski <glogow at fbihome.de>
AuthorDate: Fri Oct 5 22:02:45 2018 +0000
Commit: Jan-Marek Glogowski <glogow at fbihome.de>
CommitDate: Sat Oct 6 02:25:40 2018 +0200
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 at fbihome.de>
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()
More information about the Libreoffice-commits
mailing list