summaryrefslogtreecommitdiffstats
path: root/include/o3tl
diff options
context:
space:
mode:
authorLuboš Luňák <l.lunak@collabora.com>2021-06-09 17:10:42 +0200
committerLuboš Luňák <l.lunak@collabora.com>2021-06-09 21:20:09 +0200
commit62b58e88d897f51a7c4e12b41d14121ab8d3396f (patch)
tree291bc6fe16262c091fb4f045a0897b495044a7dd /include/o3tl
parent-Werror,-Wunused-but-set-variable (Clang 13 trunk) (diff)
downloadcore-62b58e88d897f51a7c4e12b41d14121ab8d3396f.tar.gz
core-62b58e88d897f51a7c4e12b41d14121ab8d3396f.zip
allow altering the max size of o3tl::lru_cache
Change-Id: Id119b70275e1c88a8c57f89d915241427be9dbf5 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/116927 Tested-by: Jenkins Reviewed-by: Luboš Luňák <l.lunak@collabora.com>
Diffstat (limited to 'include/o3tl')
-rw-r--r--include/o3tl/lru_map.hxx9
1 files changed, 8 insertions, 1 deletions
diff --git a/include/o3tl/lru_map.hxx b/include/o3tl/lru_map.hxx
index dc8a102977dd..41c215255c7a 100644
--- a/include/o3tl/lru_map.hxx
+++ b/include/o3tl/lru_map.hxx
@@ -50,7 +50,7 @@ private:
list_t mLruList;
map_t mLruMap;
- const size_t mMaxSize;
+ size_t mMaxSize;
void checkLRU()
{
@@ -80,6 +80,13 @@ public:
list_t().swap(mLruList);
}
+ void setMaxSize(size_t nMaxSize)
+ {
+ mMaxSize = nMaxSize ? nMaxSize : std::min(mLruMap.max_size(), mLruList.max_size());
+ while (mLruMap.size() > mMaxSize)
+ checkLRU();
+ }
+
void insert(key_value_pair_t& rPair)
{
map_iterator_t i = mLruMap.find(rPair.first);