support custom item size (cost) for o3tl::lru_map

Desktop / LibreOffice - Luboš Luňák [collabora.com] - 2 May 2022 07:26 UTC

When used with items that may vary significantly in size (such as SalLayoutGlyphsCache storing glyphs for texts of different sizes) limiting lru_map to just the number of items performs poorly, since it may use only small amount of memory if items are small or it may spent a huge amount of memory if items are large.

As extra optional template argument to o3tl::lru_map that is a functor that provides cost of item each, and the total size is based on this instead of each item having cost 1.

Change-Id: I2b326754fe63eb4bd20010d4cea615187407e26c Reviewed-on: https://gerrit.libreoffice.org/c/core/+/133672

46097559ed1c support custom item size (cost) for o3tl::lru_map
include/o3tl/lru_map.hxx | 136 ++++++++++++++++++++++++++++++++++++++++++-----
o3tl/qa/test-lru_map.cxx | 30 +++++++++++
2 files changed, 154 insertions(+), 12 deletions(-)

Upstream: cgit.freedesktop.org


  • Share