From 6cbe685381ddafa788bb96e0865dc938ee2521d1 Mon Sep 17 00:00:00 2001 From: McCabe Maxsted Date: Wed, 13 Apr 2011 16:56:48 -0700 Subject: Don't create temporary vectors in spellchecking on every draw --- linden/indra/llui/lllineeditor.cpp | 19 +++++++++---------- linden/indra/llui/lllineeditor.h | 5 +++-- linden/indra/llui/lltexteditor.cpp | 20 ++++++++++---------- linden/indra/llui/lltexteditor.h | 8 +++++--- 4 files changed, 27 insertions(+), 25 deletions(-) diff --git a/linden/indra/llui/lllineeditor.cpp b/linden/indra/llui/lllineeditor.cpp index 7618985..719b71a 100644 --- a/linden/indra/llui/lllineeditor.cpp +++ b/linden/indra/llui/lllineeditor.cpp @@ -580,9 +580,9 @@ void LLLineEditor::spell_show(void * data) } } -std::vector LLLineEditor::getMisspelledWordsPositions() +void LLLineEditor::getMisspelledWordsPositions(std::vector& misspell_positions) { - std::vector thePosesOfBadWords; + misspell_positions.clear(); const LLWString& text = mText.getWString(); //llinfos << "end of box is at " << cursorloc << " and end of text is at " << text.length() << llendl; @@ -619,14 +619,13 @@ std::vector LLLineEditor::getMisspelledWordsPositions() //turn this cursor position into a pixel pos //center = findPixelNearestPos(center-getCursor()); - thePosesOfBadWords.push_back(wordStart); - thePosesOfBadWords.push_back(wordEnd); + misspell_positions.push_back(wordStart); + misspell_positions.push_back(wordEnd); } } } wordEnd++; } - return thePosesOfBadWords; } void LLLineEditor::spell_add(void* data) @@ -2055,16 +2054,16 @@ void LLLineEditor::drawMisspelled(LLRect background) mStartSpellHere = newStartSpellHere; mEndSpellHere = newStopSpellHere; resetSpellDirty(); - misspellLocations=getMisspelledWordsPositions(); + getMisspelledWordsPositions(mMisspellLocations); } } - if (!misspellLocations.empty() && glggHunSpell->getSpellCheckHighlight()) + if (!mMisspellLocations.empty() && glggHunSpell->getSpellCheckHighlight()) { - for (int i =0; i<(int)misspellLocations.size(); i++) + for (int i =0; i<(int)mMisspellLocations.size(); i++) { - S32 wstart =findPixelNearestPos( misspellLocations[i]-getCursor()); - S32 wend = findPixelNearestPos(misspellLocations[++i]-getCursor()); + S32 wstart =findPixelNearestPos( mMisspellLocations[i]-getCursor()); + S32 wend = findPixelNearestPos(mMisspellLocations[++i]-getCursor()); S32 maxw = getRect().getWidth(); if (wend > maxw) diff --git a/linden/indra/llui/lllineeditor.h b/linden/indra/llui/lllineeditor.h index 54c0146..677d1b1 100644 --- a/linden/indra/llui/lllineeditor.h +++ b/linden/indra/llui/lllineeditor.h @@ -154,7 +154,8 @@ public: static void spell_show(void* data); static void spell_add(void* data); - std::vector getMisspelledWordsPositions(); + void getMisspelledWordsPositions(std::vector& misspell_positions); + // view overrides virtual void draw(); void autoCorrectText(); @@ -305,7 +306,7 @@ protected: std::string mPrevText; // Saved string for 'ESC' revert LLUIString mLabel; // text label that is visible when no user text provided std::string mPrevSpelledText; // saved string so we know whether to respell or not - std::vector misspellLocations; // where all the mispelled words are + std::vector mMisspellLocations; // where all the mispelled words are S32 mStartSpellHere; // the position of the first char on the screen, stored so we know when to update S32 mEndSpellHere; // the location of the last char on the screen BOOL mSpellCheckable; // set in xui as "spell_check". Default value for a field diff --git a/linden/indra/llui/lltexteditor.cpp b/linden/indra/llui/lltexteditor.cpp index 963eede..5bddcbc 100644 --- a/linden/indra/llui/lltexteditor.cpp +++ b/linden/indra/llui/lltexteditor.cpp @@ -505,10 +505,10 @@ void LLTextEditor::spell_show(void * data) } } -std::vector LLTextEditor::getMisspelledWordsPositions() +void LLTextEditor::getMisspelledWordsPositions(std::vector& misspell_positions) { resetSpellDirty(); - std::vector thePosesOfBadWords; + misspell_positions.clear(); LLWString& text = mWText; S32 wordStart=0; S32 wordEnd=spellStart;//start at the scroll start @@ -538,15 +538,15 @@ std::vector LLTextEditor::getMisspelledWordsPositions() { //misspelled word here, and you have just right clicked on it - thePosesOfBadWords.push_back(wordStart); - thePosesOfBadWords.push_back(wordEnd); + misspell_positions.push_back(wordStart); + misspell_positions.push_back(wordEnd); } } } wordEnd++; } - return thePosesOfBadWords; } + void LLTextEditor::spell_add(void* data) { SpellMenuBind* tempBind = (SpellMenuBind*)data; @@ -3280,16 +3280,16 @@ void LLTextEditor::drawMisspelled() { spellEnd = newSpellEnd; spellStart = newSpellStart; - misspellLocations = getMisspelledWordsPositions(); + getMisspelledWordsPositions(mMisspellLocations); } } //draw - if (!misspellLocations.empty() && glggHunSpell->getSpellCheckHighlight()) + if (!mMisspellLocations.empty() && glggHunSpell->getSpellCheckHighlight()) { - for (int i = 0; i<(int)misspellLocations.size() ;i++) + for (int i = 0; i<(int)mMisspellLocations.size() ;i++) { - S32 wstart = misspellLocations[i]; - S32 wend = misspellLocations[++i]; + S32 wstart = mMisspellLocations[i]; + S32 wend = mMisspellLocations[++i]; //start curor code mod const LLWString &text = mWText; const S32 text_len = getLength(); diff --git a/linden/indra/llui/lltexteditor.h b/linden/indra/llui/lltexteditor.h index 1d7a735..759cd69 100644 --- a/linden/indra/llui/lltexteditor.h +++ b/linden/indra/llui/lltexteditor.h @@ -166,8 +166,10 @@ public: static void spell_correct(void* data); static void spell_add(void* data); static void spell_show(void* data); - std::vector getMisspelledWordsPositions(); - void defineMenuCallbacks(LLMenuGL* menu); + + void getMisspelledWordsPositions(std::vector& misspell_positions); + + void defineMenuCallbacks(LLMenuGL* menu); void selectNext(const std::string& search_text_in, BOOL case_insensitive, BOOL wrap = TRUE); BOOL replaceText(const std::string& search_text, const std::string& replace_text, BOOL case_insensitive, BOOL wrap = TRUE); @@ -535,7 +537,7 @@ private: LLWString mPrevSpelledText; // saved string so we know whether to respell or not S32 spellStart; S32 spellEnd; - std::vector misspellLocations; // where all the mispelled words are + std::vector mMisspellLocations; // where all the mispelled words are BOOL mSpellCheckable; // set in xui as "spell_check". Default value for a field BOOL mAllowTranslate; // set in xui as "allow_translate". -- cgit v1.1