From 01b3bf7eefce7d7e40cd175f11eb48e175c5bea4 Mon Sep 17 00:00:00 2001 From: New Pagodi Date: Thu, 25 Jun 2020 21:45:04 -0500 Subject: [PATCH] Remove double strlen call in wxSTCListBoxD2D The length of a string in wxSTCListBoxD2D::OnDrawItemText was being calculated twice - first when measured and again when drawn. Instead store the length the first time it is calculated. Also, pass a copy of the string in wx2stclen to allow the calculation to work in ASCII builds. --- src/stc/PlatWX.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/stc/PlatWX.cpp b/src/stc/PlatWX.cpp index 1280b65595..40b78b5102 100644 --- a/src/stc/PlatWX.cpp +++ b/src/stc/PlatWX.cpp @@ -3175,8 +3175,8 @@ public: wxString ellipsizedLabel = label; wxCharBuffer buffer = wx2stc(ellipsizedLabel); - int curWidth = surface.WidthText(tempFont, buffer.data(), - wx2stclen(wxString(), buffer)); + int ellipsizedLen = wx2stclen(ellipsizedLabel, buffer); + int curWidth = surface.WidthText(tempFont, buffer.data(),ellipsizedLen); for ( int i = label.length(); curWidth > rect.GetWidth() && i; --i ) { @@ -3184,8 +3184,8 @@ public: ellipsizedLabel << "..."; buffer = wx2stc(ellipsizedLabel); - curWidth = surface.WidthText(tempFont, buffer.data(), - wx2stclen(wxString(), buffer)); + ellipsizedLen = wx2stclen(ellipsizedLabel, buffer); + curWidth = surface.WidthText(tempFont, buffer.data(),ellipsizedLen); } PRectangle prect = PRectangleFromwxRect(rect); @@ -3194,7 +3194,7 @@ public: XYPOSITION ybase = rect.GetTop() + m_surfaceFontData->GetAscent(); surface.DrawTextTransparent(prect, tempFont, ybase, buffer.data(), - wx2stclen(wxString(), buffer), fore); + ellipsizedLen, fore); tempFont.Release(); surface.Release(); }