diff options
author | Jan Holesovsky <kendy@collabora.com> | 2013-12-12 09:55:35 +0100 |
---|---|---|
committer | Jan Holesovsky <kendy@collabora.com> | 2013-12-12 09:57:42 +0100 |
commit | 62ea355b2679073b8ee326df5793231996136da9 (patch) | |
tree | 98c058ef4abc6eee09e5669f2db2764a7ba4a618 | |
parent | e74ddf429e39df01c751a3d2b452bf939fdc9a33 (diff) |
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
-rw-r--r-- | svtools/source/contnr/svlbitm.cxx | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/svtools/source/contnr/svlbitm.cxx b/svtools/source/contnr/svlbitm.cxx index ca3b3423659d..e47baaa48b14 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()); } // *************************************************************** |