better cache size limit for vcl::text::TextLayoutCache
This is not as important as SalLayoutGlyphsCache, as these should
be smaller and less needed, but still, make sure to limit the memory
the cache may use.
Change-Id: I4051331f8c5254cb5723772bac4dd1bceb9a2a41
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/133674
Tested-by: Jenkins
Reviewed-by: Luboš Luňák <l.lunak@collabora.com>
diff --git a/officecfg/registry/schema/org/openoffice/Office/Common.xcs b/officecfg/registry/schema/org/openoffice/Office/Common.xcs
index 67fa347..16d069f 100644
--- a/officecfg/registry/schema/org/openoffice/Office/Common.xcs
+++ b/officecfg/registry/schema/org/openoffice/Office/Common.xcs
@@ -1604,6 +1604,15 @@
</info>
<value>20000000</value>
</prop>
<prop oor:name="TextRunsCacheSize" oor:type="xs:long" oor:nillable="false">
<info>
<desc>Specifies the maximum cache size in bytes for all text run data used
when laying out text. Larger size may improve text drawing performance
in large documents.</desc>
<label>Text Runs Cache Size</label>
</info>
<value>100000</value>
</prop>
</group>
</group>
<group oor:name="Path">
diff --git a/vcl/source/text/TextLayoutCache.cxx b/vcl/source/text/TextLayoutCache.cxx
index e1e4321..7cbc7c4 100644
--- a/vcl/source/text/TextLayoutCache.cxx
+++ b/vcl/source/text/TextLayoutCache.cxx
@@ -24,6 +24,7 @@
#include <o3tl/hash_combine.hxx>
#include <o3tl/lru_map.hxx>
#include <vcl/lazydelete.hxx>
#include <officecfg/Office/Common.hxx>
namespace vcl::text
{
@@ -37,12 +38,24 @@ TextLayoutCache::TextLayoutCache(sal_Unicode const* pStr, sal_Int32 const nEnd)
}
}
namespace
{
struct TextLayoutCacheCost
{
size_t operator()(const std::shared_ptr<const TextLayoutCache>& item) const
{
return item->runs.size() * sizeof(item->runs.front());
}
};
} // namespace
std::shared_ptr<const TextLayoutCache> TextLayoutCache::Create(OUString const& rString)
{
typedef o3tl::lru_map<OUString, std::shared_ptr<const TextLayoutCache>, FirstCharsStringHash,
FastStringCompareEqual>
FastStringCompareEqual, TextLayoutCacheCost>
Cache;
static vcl::DeleteOnDeinit<Cache> cache(1000);
static vcl::DeleteOnDeinit<Cache> cache(
officecfg::Office::Common::Cache::Font::TextRunsCacheSize::get());
if (Cache* map = cache.get())
{
auto it = map->find(rString);