vcl/inc/TextLayoutCache.hxx | 2 ++ vcl/inc/sallayout.hxx | 1 - vcl/source/gdi/CommonSalLayout.cxx | 20 -------------------- vcl/source/gdi/impglyphitem.cxx | 2 +- vcl/source/outdev/text.cxx | 3 ++- vcl/source/text/TextLayoutCache.cxx | 25 ++++++++++++++++++++++++- 6 files changed, 29 insertions(+), 24 deletions(-)
New commits: commit 4557ea11aeda19b705b4d701bdd1b85db7f0b206 Author: Luboš Luňák <l.lu...@collabora.com> AuthorDate: Thu Apr 14 16:11:06 2022 +0200 Commit: Luboš Luňák <l.lu...@collabora.com> CommitDate: Thu Apr 14 21:48:56 2022 +0200 move vcl::text::TextLayoutCache caching to the class itself I have no idea why I did that in GenericSalLayout. Change-Id: I163b08045e7c1dcdbf35cf408525f8dbcc06c4f6 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/133019 Tested-by: Jenkins Reviewed-by: Luboš Luňák <l.lu...@collabora.com> diff --git a/vcl/inc/TextLayoutCache.hxx b/vcl/inc/TextLayoutCache.hxx index ecb85ea7043d..46e5c80dc320 100644 --- a/vcl/inc/TextLayoutCache.hxx +++ b/vcl/inc/TextLayoutCache.hxx @@ -49,6 +49,8 @@ class VCL_DLLPUBLIC TextLayoutCache public: std::vector<vcl::text::Run> runs; TextLayoutCache(sal_Unicode const* pStr, sal_Int32 const nEnd); + // Creates a cached instance. + static std::shared_ptr<const vcl::text::TextLayoutCache> Create(OUString const&); }; struct FirstCharsStringHash diff --git a/vcl/inc/sallayout.hxx b/vcl/inc/sallayout.hxx index 894be0a3098b..75f7cb3c6ea0 100644 --- a/vcl/inc/sallayout.hxx +++ b/vcl/inc/sallayout.hxx @@ -113,7 +113,6 @@ public: void AdjustLayout(vcl::text::ImplLayoutArgs&) final override; bool LayoutText(vcl::text::ImplLayoutArgs&, const SalLayoutGlyphsImpl*) final override; void DrawText(SalGraphics&) const final override; - static std::shared_ptr<const vcl::text::TextLayoutCache> CreateTextLayoutCache(OUString const&); SalLayoutGlyphs GetGlyphs() const final override; bool IsKashidaPosValid(int nCharPos) const final override; diff --git a/vcl/source/gdi/CommonSalLayout.cxx b/vcl/source/gdi/CommonSalLayout.cxx index 628938c5b123..0007e3f355d1 100644 --- a/vcl/source/gdi/CommonSalLayout.cxx +++ b/vcl/source/gdi/CommonSalLayout.cxx @@ -21,11 +21,8 @@ #include <sal/log.hxx> #include <unotools/configmgr.hxx> -#include <o3tl/hash_combine.hxx> -#include <o3tl/lru_map.hxx> #include <o3tl/temporary.hxx> -#include <vcl/lazydelete.hxx> #include <vcl/unohelp.hxx> #include <vcl/font/Feature.hxx> #include <vcl/font/FeatureParser.hxx> @@ -156,23 +153,6 @@ namespace { } // namespace -std::shared_ptr<const vcl::text::TextLayoutCache> GenericSalLayout::CreateTextLayoutCache(OUString const& rString) -{ - typedef o3tl::lru_map<OUString, std::shared_ptr<const vcl::text::TextLayoutCache>, - vcl::text::FirstCharsStringHash, vcl::text::FastStringCompareEqual> Cache; - static vcl::DeleteOnDeinit< Cache > cache( 1000 ); - if( Cache* map = cache.get()) - { - auto it = map->find(rString); - if( it != map->end()) - return it->second; - auto ret = std::make_shared<const vcl::text::TextLayoutCache>(rString.getStr(), rString.getLength()); - map->insert( { rString, ret } ); - return ret; - } - return std::make_shared<const vcl::text::TextLayoutCache>(rString.getStr(), rString.getLength()); -} - SalLayoutGlyphs GenericSalLayout::GetGlyphs() const { SalLayoutGlyphs glyphs; diff --git a/vcl/source/gdi/impglyphitem.cxx b/vcl/source/gdi/impglyphitem.cxx index d581715dc9cd..0268eb3861c0 100644 --- a/vcl/source/gdi/impglyphitem.cxx +++ b/vcl/source/gdi/impglyphitem.cxx @@ -256,7 +256,7 @@ SalLayoutGlyphsCache::GetLayoutGlyphs(VclPtr<const OutputDevice> outputDevice, c std::shared_ptr<const vcl::text::TextLayoutCache> tmpLayoutCache; if (layoutCache == nullptr) { - tmpLayoutCache = OutputDevice::CreateTextLayoutCache(text); + tmpLayoutCache = vcl::text::TextLayoutCache::Create(text); layoutCache = tmpLayoutCache.get(); } std::unique_ptr<SalLayout> layout = outputDevice->ImplLayout( diff --git a/vcl/source/outdev/text.cxx b/vcl/source/outdev/text.cxx index 522fd348c7ee..840341502beb 100644 --- a/vcl/source/outdev/text.cxx +++ b/vcl/source/outdev/text.cxx @@ -51,6 +51,7 @@ #include <textlineinfo.hxx> #include <impglyphitem.hxx> #include <optional> +#include <TextLayoutCache.hxx> #include <font/PhysicalFontFace.hxx> #define TEXT_DRAW_ELLIPSIS (DrawTextFlags::EndEllipsis | DrawTextFlags::PathEllipsis | DrawTextFlags::NewsEllipsis) @@ -1459,7 +1460,7 @@ std::unique_ptr<SalLayout> OutputDevice::ImplLayout(const OUString& rOrigStr, std::shared_ptr<const vcl::text::TextLayoutCache> OutputDevice::CreateTextLayoutCache( OUString const& rString) { - return GenericSalLayout::CreateTextLayoutCache(rString); + return vcl::text::TextLayoutCache::Create(rString); } bool OutputDevice::GetTextIsRTL( const OUString& rString, sal_Int32 nIndex, sal_Int32 nLen ) const diff --git a/vcl/source/text/TextLayoutCache.cxx b/vcl/source/text/TextLayoutCache.cxx index 00e9f9405358..e1e4321a98d3 100644 --- a/vcl/source/text/TextLayoutCache.cxx +++ b/vcl/source/text/TextLayoutCache.cxx @@ -17,9 +17,14 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#include <scrptrun.h> #include <TextLayoutCache.hxx> +#include <scrptrun.h> + +#include <o3tl/hash_combine.hxx> +#include <o3tl/lru_map.hxx> +#include <vcl/lazydelete.hxx> + namespace vcl::text { TextLayoutCache::TextLayoutCache(sal_Unicode const* pStr, sal_Int32 const nEnd) @@ -31,6 +36,24 @@ TextLayoutCache::TextLayoutCache(sal_Unicode const* pStr, sal_Int32 const nEnd) aScriptRun.getScriptCode()); } } + +std::shared_ptr<const TextLayoutCache> TextLayoutCache::Create(OUString const& rString) +{ + typedef o3tl::lru_map<OUString, std::shared_ptr<const TextLayoutCache>, FirstCharsStringHash, + FastStringCompareEqual> + Cache; + static vcl::DeleteOnDeinit<Cache> cache(1000); + if (Cache* map = cache.get()) + { + auto it = map->find(rString); + if (it != map->end()) + return it->second; + auto ret = std::make_shared<const TextLayoutCache>(rString.getStr(), rString.getLength()); + map->insert({ rString, ret }); + return ret; + } + return std::make_shared<const TextLayoutCache>(rString.getStr(), rString.getLength()); +} } /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */