From 4f4a6d45880d13816fbbe9850fb64fa8d9b9f6b6 Mon Sep 17 00:00:00 2001 From: Shyotl Date: Sat, 4 Jun 2016 01:19:12 -0500 Subject: [PATCH] Avoid excessive string allocations in updateLineStartList. Fixes some performance issues. --- indra/llui/lltexteditor.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/indra/llui/lltexteditor.cpp b/indra/llui/lltexteditor.cpp index 0412c302e..346646c37 100644 --- a/indra/llui/lltexteditor.cpp +++ b/indra/llui/lltexteditor.cpp @@ -551,8 +551,17 @@ void LLTextEditor::updateLineStartList(S32 startpos) } } else - { - const llwchar* str = mWText.c_str() + start_idx; + { + //Scratch buffer. Avoid needless realloc. + static LLWString buf; + + if(start_idx) + { + buf.resize(end_idx - start_idx); + std::copy(mWText.begin() + start_idx, mWText.begin() + end_idx, buf.begin()); + } + const LLWString& str = start_idx ? buf : mWText; + S32 drawn = mGLFont->maxDrawableChars(str, (F32)abs(mTextRect.getWidth()) - line_width, end_idx - start_idx, mWordWrap ? LLFontGL::WORD_BOUNDARY_IF_POSSIBLE : LLFontGL::ANYWHERE, mAllowEmbeddedItems ); if( 0 == drawn && line_width == start_x)