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

Jan Holesovsky kendy at collabora.com
Thu Dec 12 00:58:09 PST 2013


 svtools/source/contnr/svlbitm.cxx |   20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)

New commits:
commit 62ea355b2679073b8ee326df5793231996136da9
Author: Jan Holesovsky <kendy at collabora.com>
Date:   Thu Dec 12 09:55:35 2013 +0100

    fdo#72125: GetTextWidth() can get very expensive.
    
    Let's just count an approximate width using a cached value when we have too
    many entries.
    
    Change-Id: I2113887c477bc774dd00df538ec1a01f102f4726

diff --git a/svtools/source/contnr/svlbitm.cxx b/svtools/source/contnr/svlbitm.cxx
index ca3b342..e47baaa 100644
--- a/svtools/source/contnr/svlbitm.cxx
+++ b/svtools/source/contnr/svlbitm.cxx
@@ -247,7 +247,25 @@ void SvLBoxString::InitViewData(
     DBG_CHKTHIS(SvLBoxString,0);
     if( !pViewData )
         pViewData = pView->GetViewDataItem( pEntry, this );
-    pViewData->maSize = Size(pView->GetTextWidth(maText), pView->GetTextHeight());
+
+    // fdo#72125: GetTextWidth() can get very expensive; let's just count
+    // an approximate width using a cached value when we have many entries
+    long nTextWidth;
+    if (pView->GetEntryCount() > 100)
+    {
+        static SvTreeListBox *pPreviousView = NULL;
+        static float fApproximateCharWidth = 0.0;
+        if (pPreviousView != pView)
+        {
+            pPreviousView = pView;
+            fApproximateCharWidth = pView->approximate_char_width();
+        }
+        nTextWidth = maText.getLength() * fApproximateCharWidth;
+    }
+    else
+        nTextWidth = pView->GetTextWidth(maText);
+
+    pViewData->maSize = Size(nTextWidth, pView->GetTextHeight());
 }
 
 // ***************************************************************


More information about the Libreoffice-commits mailing list