[Libreoffice-commits] core.git: sw/source

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Fri Oct 12 18:38:57 UTC 2018


 sw/source/core/txtnode/fntcache.cxx |   13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

New commits:
commit c7b83934fcf4120c1a4cba8e1eaf9c7aef9edc82
Author:     Miklos Vajna <vmiklos at collabora.co.uk>
AuthorDate: Fri Oct 12 17:57:36 2018 +0200
Commit:     Miklos Vajna <vmiklos at collabora.co.uk>
CommitDate: Fri Oct 12 20:38:31 2018 +0200

    tdf#119992 sw: compare sub-strings in SwTextGlyphsKey comparison
    
    Time till the layout reaches idle, before:
    
    77.412 seconds
    
    After:
    
    26.221 seconds (33% of baseline) for me.
    
    Change-Id: Idd0c5255070c836fde2fb048b02c851f5f2321e4
    Reviewed-on: https://gerrit.libreoffice.org/61724
    Reviewed-by: Miklos Vajna <vmiklos at collabora.co.uk>
    Tested-by: Jenkins

diff --git a/sw/source/core/txtnode/fntcache.cxx b/sw/source/core/txtnode/fntcache.cxx
index 740710c6c27e..9166965dfb7e 100644
--- a/sw/source/core/txtnode/fntcache.cxx
+++ b/sw/source/core/txtnode/fntcache.cxx
@@ -144,9 +144,16 @@ bool operator<(const SwTextGlyphsKey& l, const SwTextGlyphsKey& r)
     if (l.m_nLength > r.m_nLength)
         return false;
 
-    // Comparing strings is expensive, so compare them only at the end, and
-    // only once.
-    sal_Int32 nRet = l.m_aText.compareTo(r.m_aText);
+    // Comparing strings is expensive, so compare them:
+    // - only at the end of this function
+    // - only once
+    // - only the relevant substring (if the index/length is not out of bounds)
+    sal_Int32 nRet = 0;
+    if (l.m_nLength < 0 || l.m_nIndex < 0 || l.m_nIndex + l.m_nLength > l.m_aText.getLength())
+        nRet = l.m_aText.compareTo(r.m_aText);
+    else
+        nRet = memcmp(l.m_aText.getStr() + l.m_nIndex, r.m_aText.getStr() + r.m_nIndex,
+                      l.m_nLength * sizeof(sal_Unicode));
     if (nRet < 0)
         return true;
     if (nRet > 0)


More information about the Libreoffice-commits mailing list