From 0cc0db81afec26842ea9887aa50afb072d13914c Mon Sep 17 00:00:00 2001 From: Andrey Lihatskiy Date: Tue, 25 Feb 2025 06:43:52 +0200 Subject: #3422 Better handling of Lua syntax --- indra/newview/llscripteditor.cpp | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) (limited to 'indra/newview/llscripteditor.cpp') diff --git a/indra/newview/llscripteditor.cpp b/indra/newview/llscripteditor.cpp index 59cf3ac02b..0edaf43753 100644 --- a/indra/newview/llscripteditor.cpp +++ b/indra/newview/llscripteditor.cpp @@ -141,20 +141,24 @@ void LLScriptEditor::drawLineNumbers() } } -void LLScriptEditor::initKeywords() +void LLScriptEditor::initKeywords(bool luau_language) { - mKeywords.initialize(LLSyntaxIdLSL::getInstance()->getKeywordsXML()); + mKeywordsLua.initialize(LLSyntaxLua::getInstance()->getKeywordsXML(), true); + mKeywordsLSL.initialize(LLSyntaxIdLSL::getInstance()->getKeywordsXML(), false); + + mLuauLanguage = luau_language; + } void LLScriptEditor::loadKeywords() { LL_PROFILE_ZONE_SCOPED; - mKeywords.processTokens(); + getKeywords().processTokens(); LLStyleConstSP style = new LLStyle(LLStyle::Params().font(getScriptFont()).color(mDefaultColor.get())); segment_vec_t segment_list; - mKeywords.findSegments(&segment_list, getWText(), *this, style); + getKeywords().findSegments(&segment_list, getWText(), *this, style); mSegments.clear(); segment_set_t::iterator insert_it = mSegments.begin(); @@ -166,7 +170,7 @@ void LLScriptEditor::loadKeywords() void LLScriptEditor::updateSegments() { - if (mReflowIndex < S32_MAX && mKeywords.isLoaded() && mParseOnTheFly) + if (mReflowIndex < S32_MAX && getKeywords().isLoaded() && mParseOnTheFly) { LL_PROFILE_ZONE_SCOPED; @@ -174,7 +178,7 @@ void LLScriptEditor::updateSegments() // HACK: No non-ascii keywords for now segment_vec_t segment_list; - mKeywords.findSegments(&segment_list, getWText(), *this, style); + getKeywords().findSegments(&segment_list, getWText(), *this, style); clearSegments(); for (segment_vec_t::iterator list_it = segment_list.begin(); list_it != segment_list.end(); ++list_it) @@ -194,6 +198,21 @@ void LLScriptEditor::clearSegments() } } +LLKeywords::keyword_iterator_t LLScriptEditor::keywordsBegin() +{ + return mLuauLanguage ? mKeywordsLua.begin() : mKeywordsLSL.begin(); +} + +LLKeywords::keyword_iterator_t LLScriptEditor::keywordsEnd() +{ + return mLuauLanguage ? mKeywordsLua.end() : mKeywordsLSL.end(); +} + +LLKeywords& LLScriptEditor::getKeywords() +{ + return mLuauLanguage ? mKeywordsLua : mKeywordsLSL; +} + // Most of this is shamelessly copied from LLTextBase void LLScriptEditor::drawSelectionBackground() { -- cgit v1.3 From 668c8c61a12842d33cb83b79ba3d68ba3db7aa8b Mon Sep 17 00:00:00 2001 From: Andrey Lihatskiy Date: Fri, 7 Mar 2025 05:01:56 +0200 Subject: #3422 Code cleanup --- indra/newview/llpreviewscript.cpp | 6 +++--- indra/newview/llpreviewscript.h | 33 ++++++++++++++++----------------- indra/newview/llscripteditor.cpp | 8 ++++---- indra/newview/llscripteditor.h | 2 -- 4 files changed, 23 insertions(+), 26 deletions(-) (limited to 'indra/newview/llscripteditor.cpp') diff --git a/indra/newview/llpreviewscript.cpp b/indra/newview/llpreviewscript.cpp index 28988f9564..9449768d79 100644 --- a/indra/newview/llpreviewscript.cpp +++ b/indra/newview/llpreviewscript.cpp @@ -396,9 +396,9 @@ LLScriptEdCore::LLScriptEdCore( LLScriptEdContainer* container, const std::string& sample, const LLHandle& floater_handle, - void (*load_callback)(void*), - void (*save_callback)(void*, bool), - void (*search_replace_callback) (void* userdata), + script_ed_callback_t load_callback, + save_callback_t save_callback, + script_ed_callback_t search_replace_callback, void* userdata, bool live, S32 bottom_pad) diff --git a/indra/newview/llpreviewscript.h b/indra/newview/llpreviewscript.h index 430ca4cc76..117be03fc6 100644 --- a/indra/newview/llpreviewscript.h +++ b/indra/newview/llpreviewscript.h @@ -82,15 +82,19 @@ class LLScriptEdCore : public LLPanel friend class LLScriptEdContainer; friend class LLFloaterGotoLine; +public: + typedef boost::function script_ed_callback_t; + typedef boost::function save_callback_t; + protected: // Supposed to be invoked only by the container. LLScriptEdCore( LLScriptEdContainer* container, const std::string& sample, const LLHandle& floater_handle, - void (*load_callback)(void* userdata), - void (*save_callback)(void* userdata, bool close_after_save), - void (*search_replace_callback)(void* userdata), + script_ed_callback_t load_callback, + save_callback_t save_callback, + script_ed_callback_t search_replace_callback, void* userdata, bool live, S32 bottom_pad = 0); // pad below bottom row of buttons @@ -139,11 +143,11 @@ public: LLUUID getAssociatedExperience()const; void setAssociatedExperience( const LLUUID& experience_id ); - void setScriptName(const std::string& name){mScriptName = name;}; + void setScriptName(const std::string& name) { mScriptName = name; } - void setItemRemoved(bool script_removed){mScriptRemoved = script_removed;}; + void setItemRemoved(bool script_removed) { mScriptRemoved = script_removed; } - void setAssetID( const LLUUID& asset_id){ mAssetID = asset_id; }; + void setAssetID(const LLUUID& asset_id) { mAssetID = asset_id; } LLUUID getAssetID() { return mAssetID; } bool isFontSizeChecked(const LLSD &userdata); @@ -152,16 +156,15 @@ public: virtual bool handleKeyHere(KEY key, MASK mask); void selectAll() { mEditor->selectAll(); } + void enableSave(bool b) { mEnableSave = b; } + bool hasChanged(); + private: void onBtnDynamicHelp(); void onBtnUndoChanges(); - bool hasChanged(); - void selectFirstError(); - void enableSave(bool b) {mEnableSave = b;} - protected: void deleteBridges(); void setHelpPage(const std::string& help_string); @@ -176,9 +179,9 @@ private: std::string mSampleText; std::string mScriptName; LLScriptEditor* mEditor; - void (*mLoadCallback)(void* userdata); - void (*mSaveCallback)(void* userdata, bool close_after_save); - void (*mSearchReplaceCallback) (void* userdata); + script_ed_callback_t mLoadCallback; + save_callback_t mSaveCallback; + script_ed_callback_t mSearchReplaceCallback; void* mUserdata; LLComboBox *mFunctions; bool mForceClose; @@ -204,7 +207,6 @@ private: public: boost::signals2::connection mSyntaxIDConnection; - }; class LLScriptEdContainer : public LLPreview @@ -269,10 +271,8 @@ protected: S32 mPendingUploads; LLScriptMovedObserver* mItemObserver; - }; - // Used to view and edit an LSL script that is attached to an object. class LLLiveLSLEditor : public LLScriptEdContainer { @@ -280,7 +280,6 @@ class LLLiveLSLEditor : public LLScriptEdContainer public: LLLiveLSLEditor(const LLSD& key); - static void processScriptRunningReply(LLMessageSystem* msg, void**); virtual void callbackLSLCompileSucceeded(const LLUUID& task_id, diff --git a/indra/newview/llscripteditor.cpp b/indra/newview/llscripteditor.cpp index 0edaf43753..2a9dd73936 100644 --- a/indra/newview/llscripteditor.cpp +++ b/indra/newview/llscripteditor.cpp @@ -45,7 +45,8 @@ LLScriptEditor::Params::Params() LLScriptEditor::LLScriptEditor(const Params& p) : LLTextEditor(p) , mShowLineNumbers(p.show_line_numbers), - mUseDefaultFontSize(p.default_font_size) + mUseDefaultFontSize(p.default_font_size), + mLuauLanguage(false) { if (mShowLineNumbers) { @@ -200,12 +201,12 @@ void LLScriptEditor::clearSegments() LLKeywords::keyword_iterator_t LLScriptEditor::keywordsBegin() { - return mLuauLanguage ? mKeywordsLua.begin() : mKeywordsLSL.begin(); + return getKeywords().begin(); } LLKeywords::keyword_iterator_t LLScriptEditor::keywordsEnd() { - return mLuauLanguage ? mKeywordsLua.end() : mKeywordsLSL.end(); + return getKeywords().end(); } LLKeywords& LLScriptEditor::getKeywords() @@ -237,7 +238,6 @@ void LLScriptEditor::drawSelectionBackground() ++rect_it) { LLRect selection_rect = *rect_it; - selection_rect = *rect_it; selection_rect.translate(mVisibleTextRect.mLeft - content_display_rect.mLeft, mVisibleTextRect.mBottom - content_display_rect.mBottom); gl_rect_2d(selection_rect, selection_color); } diff --git a/indra/newview/llscripteditor.h b/indra/newview/llscripteditor.h index ad61405917..1586a43160 100644 --- a/indra/newview/llscripteditor.h +++ b/indra/newview/llscripteditor.h @@ -67,8 +67,6 @@ private: void drawLineNumbers(); /* virtual */ void updateSegments(); /* virtual */ void drawSelectionBackground(); - void loadKeywords(const std::string& filename_keywords, - const std::string& filename_colors); LLKeywords mKeywordsLua; LLKeywords mKeywordsLSL; -- cgit v1.3 From 732b96958f0677674ca2756ce6a692f54bfd6a28 Mon Sep 17 00:00:00 2001 From: Darl Date: Wed, 31 Dec 2025 09:22:35 -0600 Subject: Update LLScriptEditor and friends to index line numbers from 1 when editing in Lua (#5190) * Update LLScriptEditor to index line numbers from 1 when editing in Lua This is to match server-generated runtime errors that reference lines. Signed-off-by: Darl * Update LLFloaterGotoLine and LLPreviewScript to support Lua's line/col expectations Existing behavior for LSL is preserved Fixes a bug in previous commit that causes the line number shown near the bottom of the script edit floater to be off by 1 when displaying a Lua script. Signed-off-by: Darl * Update script editor error console goto error to reflect Lua line nums Signed-off-by: Darl --------- Signed-off-by: Darl --- indra/newview/llfloatergotoline.cpp | 8 +++++--- indra/newview/llpreviewscript.cpp | 3 +++ indra/newview/llscripteditor.cpp | 2 +- 3 files changed, 9 insertions(+), 4 deletions(-) (limited to 'indra/newview/llscripteditor.cpp') diff --git a/indra/newview/llfloatergotoline.cpp b/indra/newview/llfloatergotoline.cpp index 09ca0ab530..6b3f16ecf5 100644 --- a/indra/newview/llfloatergotoline.cpp +++ b/indra/newview/llfloatergotoline.cpp @@ -109,8 +109,9 @@ void LLFloaterGotoLine::handleBtnGoto() { if (mEditorCore && mEditorCore->mEditor) { + S32 target_row = mEditorCore->mEditor->getIsLuauLanguage() ? (row - 1) : row; mEditorCore->mEditor->deselect(); - mEditorCore->mEditor->setCursor(row, column); + mEditorCore->mEditor->setCursor(target_row, column); mEditorCore->mEditor->setFocus(true); } } @@ -144,12 +145,13 @@ void LLFloaterGotoLine::onGotoBoxCommit() { if (mEditorCore && mEditorCore->mEditor) { - mEditorCore->mEditor->setCursor(row, column); + S32 target_row = mEditorCore->mEditor->getIsLuauLanguage() ? (row - 1) : row; + mEditorCore->mEditor->setCursor(target_row, column); S32 rownew = 0; S32 columnnew = 0; mEditorCore->mEditor->getCurrentLineAndColumn( &rownew, &columnnew, false ); // don't include wordwrap - if (rownew == row && columnnew == column) + if (rownew == target_row && columnnew == column) { mEditorCore->mEditor->deselect(); mEditorCore->mEditor->setFocus(true); diff --git a/indra/newview/llpreviewscript.cpp b/indra/newview/llpreviewscript.cpp index b3e53df6d8..01167a43b8 100644 --- a/indra/newview/llpreviewscript.cpp +++ b/indra/newview/llpreviewscript.cpp @@ -751,6 +751,8 @@ void LLScriptEdCore::draw() S32 line = 0; S32 column = 0; mEditor->getCurrentLineAndColumn( &line, &column, false ); // don't include wordwrap + line = mEditor->getIsLuauLanguage() ? (line + 1) : line; + column = mEditor->getIsLuauLanguage() ? (column + 1) : column; LLStringUtil::format_map_t args; std::string cursor_pos; args["[LINE]"] = llformat ("%d", line); @@ -1211,6 +1213,7 @@ void LLScriptEdCore::onErrorList(LLUICtrl*, void* user_data) sscanf(line.c_str(), "%d %d", &row, &column); //LL_INFOS() << "LLScriptEdCore::onErrorList() - " << row << ", " //<< column << LL_ENDL; + row = (self->mEditor->getIsLuauLanguage() ? row - 1 : row); self->mEditor->setCursor(row, column); self->mEditor->setFocus(true); } diff --git a/indra/newview/llscripteditor.cpp b/indra/newview/llscripteditor.cpp index 2a9dd73936..d171d785a7 100644 --- a/indra/newview/llscripteditor.cpp +++ b/indra/newview/llscripteditor.cpp @@ -120,7 +120,7 @@ void LLScriptEditor::drawLineNumbers() // draw the line numbers if(line.mLineNum != last_line_num && line.mRect.mTop <= scrolled_view_rect.mTop) { - const LLWString ltext = utf8str_to_wstring(llformat("%d", line.mLineNum )); + const LLWString ltext = utf8str_to_wstring(llformat("%d", mLuauLanguage ? line.mLineNum + 1 : line.mLineNum)); bool is_cur_line = cursor_line == line.mLineNum; const U8 style = is_cur_line ? LLFontGL::BOLD : LLFontGL::NORMAL; const LLColor4& fg_color = is_cur_line ? mCursorColor : mReadOnlyFgColor; -- cgit v1.3 From 5fa0910d6176f610de45548d8558fb53f00a0eda Mon Sep 17 00:00:00 2001 From: Andrey Lihatskiy Date: Mon, 12 Jan 2026 05:23:33 +0200 Subject: #5278 Move syntax tokenization off UI thread; apply results on main thread --- indra/llui/llkeywords.cpp | 109 ++++++++++------ indra/llui/llkeywords.h | 20 +++ indra/newview/llscripteditor.cpp | 275 ++++++++++++++++++++++++++++++++++++--- indra/newview/llscripteditor.h | 12 +- 4 files changed, 354 insertions(+), 62 deletions(-) (limited to 'indra/newview/llscripteditor.cpp') diff --git a/indra/llui/llkeywords.cpp b/indra/llui/llkeywords.cpp index 2168ba2382..0ada54df06 100644 --- a/indra/llui/llkeywords.cpp +++ b/indra/llui/llkeywords.cpp @@ -498,41 +498,25 @@ bool LLKeywords::WStringMapIndex::operator<(const LLKeywords::WStringMapIndex &o LLTrace::BlockTimerStatHandle FTM_SYNTAX_COLORING("Syntax Coloring"); -// Walk through a string, applying the rules specified by the keyword token list and -// create a list of color segments. -void LLKeywords::findSegments(std::vector* seg_list, const LLWString& wtext, LLTextEditor& editor, LLStyleConstSP style) +void LLKeywords::collectSegmentOps(segment_ops_t& ops, const LLWString& wtext, bool disable_syntax_highlighting) const { - LL_RECORD_BLOCK_TIME(FTM_SYNTAX_COLORING); + ops.clear(); - if( wtext.empty() ) + if (wtext.empty()) { return; } - // Clear the segment list - seg_list->clear(); - // Reserve capacity for segments based on an estimated average of 8 characters per segment. - constexpr size_t AVERAGE_SEGMENT_LENGTH = 8; - seg_list->reserve(wtext.size() / AVERAGE_SEGMENT_LENGTH); - - S32 text_len = static_cast(wtext.size()) + 1; - - seg_list->push_back( new LLNormalTextSegment( style, 0, text_len, editor ) ); - - static LLCachedControl sDisableSyntaxHighlighting(gSavedSettings, "ScriptEditorDisableSyntaxHighlight", false); - const bool disable_syntax_highlighting = sDisableSyntaxHighlighting; - const llwchar* base = wtext.c_str(); const llwchar* cur = base; + while( *cur ) { if( *cur == '\n' || cur == base ) { if( *cur == '\n' ) { - LLTextSegmentPtr text_segment = new LLLineBreakTextSegment(style, (S32)(cur - base)); - text_segment->setToken( 0 ); - insertSegment( *seg_list, text_segment, text_len, style, editor); + ops.push_back({SegmentOp::OP_LINE_BREAK, (S32)(cur - base), 0, nullptr}); cur++; if( !*cur || *cur == '\n' ) { @@ -570,8 +554,7 @@ void LLKeywords::findSegments(std::vector* seg_list, const LLW } S32 seg_end = (S32)(cur - base); - //create segments from seg_start to seg_end - insertSegments(wtext, *seg_list,cur_token, text_len, seg_start, seg_end, style, editor); + ops.push_back({SegmentOp::OP_TOKEN, seg_start, seg_end, cur_token}); line_done = true; // to break out of second loop. break; } @@ -646,7 +629,6 @@ void LLKeywords::findSegments(std::vector* seg_list, const LLW if (*p == '[') { p++; // skip the second [ - const llwchar* content_start = p; // Build the closing pattern: ] + level equals + ] // Search for it in the remaining text @@ -667,7 +649,7 @@ void LLKeywords::findSegments(std::vector* seg_list, const LLW // Found the matching close seg_end = (S32)(close_check + 1 - base); cur = close_check + 1; - insertSegments(wtext, *seg_list, cur_delimiter, text_len, seg_start, seg_end, style, editor); + ops.push_back({SegmentOp::OP_TOKEN, seg_start, seg_end, cur_delimiter}); break; } } @@ -677,9 +659,9 @@ void LLKeywords::findSegments(std::vector* seg_list, const LLW if (!*p) { // No closing found, highlight to end of file - seg_end = text_len - 1; + seg_end = static_cast(wtext.size()); cur = base + seg_end; - insertSegments(wtext, *seg_list, cur_delimiter, text_len, seg_start, seg_end, style, editor); + ops.push_back({SegmentOp::OP_TOKEN, seg_start, seg_end, cur_delimiter}); } continue; } @@ -761,7 +743,7 @@ void LLKeywords::findSegments(std::vector* seg_list, const LLW seg_end = seg_start + between_delimiters + cur_delimiter->getLengthHead(); } - insertSegments(wtext, *seg_list, cur_delimiter, text_len, seg_start, seg_end, style, editor); + ops.push_back({SegmentOp::OP_TOKEN, seg_start, seg_end, cur_delimiter}); // Note: we don't increment cur, since the end of one delimited seg may be immediately // followed by the start of another one. continue; @@ -794,13 +776,12 @@ void LLKeywords::findSegments(std::vector* seg_list, const LLW S32 seg_end = seg_start + seg_len; // First try to match the whole token (including dots for Lua namespaces) - word_token_map_t::iterator map_iter = mWordTokenMap.find(WStringMapIndex(word_start, seg_len)); + word_token_map_t::const_iterator map_iter = mWordTokenMap.find(WStringMapIndex(word_start, seg_len)); if (map_iter != mWordTokenMap.end()) { // Found a match for the complete token (including any namespace) - LLKeywordToken* cur_token = map_iter->second; - insertSegments(wtext, *seg_list, cur_token, text_len, seg_start, seg_end, style, editor); + ops.push_back({SegmentOp::OP_TOKEN, seg_start, seg_end, map_iter->second}); } else if (namespace_dots > 0 && mLuauLanguage) { @@ -815,8 +796,7 @@ void LLKeywords::findSegments(std::vector* seg_list, const LLW if (map_iter != mWordTokenMap.end()) { // Found a match for the namespace prefix, highlight just that part - LLKeywordToken* cur_token = map_iter->second; - insertSegments(wtext, *seg_list, cur_token, text_len, seg_start, seg_start + prefix_len, style, editor); + ops.push_back({SegmentOp::OP_TOKEN, seg_start, seg_start + prefix_len, map_iter->second}); // Now try to match the function part (after the dot) const llwchar* func_part = last_dot + 1; @@ -830,13 +810,7 @@ void LLKeywords::findSegments(std::vector* seg_list, const LLW if (map_iter != mWordTokenMap.end()) { // Found a match for the function part - LLKeywordToken* cur_token = map_iter->second; - insertSegments(wtext, *seg_list, cur_token, text_len, seg_start, seg_end, style, editor); - } - else - { - // No token found, continue without incrementing cur - // since we already advanced it while collecting the word + ops.push_back({SegmentOp::OP_TOKEN, seg_start, seg_end, map_iter->second}); } } } @@ -854,6 +828,61 @@ void LLKeywords::findSegments(std::vector* seg_list, const LLW } } +void LLKeywords::applySegmentOps(std::vector *seg_list, + const LLWString& wtext, + const segment_ops_t& ops, + LLTextEditor& editor, + LLStyleConstSP style) +{ + if (wtext.empty()) + { + return; + } + + // Clear the segment list + seg_list->clear(); + // Reserve capacity for segments based on an estimated average of 8 characters per segment. + constexpr size_t AVERAGE_SEGMENT_LENGTH = 8; + seg_list->reserve(wtext.size() / AVERAGE_SEGMENT_LENGTH); + + S32 text_len = static_cast(wtext.size()) + 1; + + seg_list->push_back( new LLNormalTextSegment( style, 0, text_len, editor ) ); + + for (const auto& op : ops) + { + if (op.type == SegmentOp::OP_LINE_BREAK) + { + LLTextSegmentPtr text_segment = new LLLineBreakTextSegment(style, op.start); + text_segment->setToken( 0 ); + insertSegment( *seg_list, text_segment, text_len, style, editor); + } + else + { + insertSegments(wtext, *seg_list, op.token, text_len, op.start, op.end, style, editor); + } + } +} + +// Walk through a string, applying the rules specified by the keyword token list and +// create a list of color segments. +void LLKeywords::findSegments(std::vector* seg_list, const LLWString& wtext, LLTextEditor& editor, LLStyleConstSP style) +{ + LL_RECORD_BLOCK_TIME(FTM_SYNTAX_COLORING); + + if( wtext.empty() ) + { + return; + } + + static LLCachedControl sDisableSyntaxHighlighting(gSavedSettings, "ScriptEditorDisableSyntaxHighlight", false); + const bool disable_syntax_highlighting = sDisableSyntaxHighlighting; + + segment_ops_t ops; + collectSegmentOps(ops, wtext, disable_syntax_highlighting); + applySegmentOps(seg_list, wtext, ops, editor, style); +} + void LLKeywords::insertSegments(const LLWString& wtext, std::vector& seg_list, LLKeywordToken* cur_token, S32 text_len, S32 seg_start, S32 seg_end, LLStyleConstSP style, LLTextEditor& editor ) { std::string::size_type pos = wtext.find('\n',seg_start); diff --git a/indra/llui/llkeywords.h b/indra/llui/llkeywords.h index 3a02f0e68e..b8689a0e88 100644 --- a/indra/llui/llkeywords.h +++ b/indra/llui/llkeywords.h @@ -36,6 +36,7 @@ #include #include #include +#include #include "llpointer.h" class LLTextSegment; @@ -124,6 +125,25 @@ public: const LLWString& text, class LLTextEditor& editor, LLStyleConstSP style); + struct SegmentOp + { + enum EOpType + { + OP_LINE_BREAK, + OP_TOKEN + }; + EOpType type; + S32 start; + S32 end; + LLKeywordToken* token; + }; + typedef std::vector segment_ops_t; + void collectSegmentOps(segment_ops_t& ops, const LLWString& text, bool disable_syntax_highlighting) const; + void applySegmentOps(std::vector *seg_list, + const LLWString& text, + const segment_ops_t& ops, + class LLTextEditor& editor, + LLStyleConstSP style); void initialize(LLSD SyntaxXML, bool luau_language = false); void processTokens(); diff --git a/indra/newview/llscripteditor.cpp b/indra/newview/llscripteditor.cpp index d171d785a7..871210ea6d 100644 --- a/indra/newview/llscripteditor.cpp +++ b/indra/newview/llscripteditor.cpp @@ -31,6 +31,173 @@ #include "llsyntaxid.h" #include "lllocalcliprect.h" #include "llviewercontrol.h" +#include "llworkerthread.h" +#include + +static LLWorkerThread& getSyntaxWorkerThread() +{ + static LLWorkerThread* sThread = new LLWorkerThread("SyntaxParse", true); + return *sThread; +} + +class LLScriptEditorSyntaxWorker final : public LLWorkerClass +{ +public: + struct Request + { + LLWString text; + S32 text_generation = 0; + U32 keywords_generation = 0; + bool disable_highlight = false; + LLKeywords* keywords = nullptr; + }; + + struct Result + { + LLWString text; + LLKeywords::segment_ops_t ops; + S32 text_generation = 0; + U32 keywords_generation = 0; + bool disable_highlight = false; + LLKeywords* keywords = nullptr; + }; + + LLScriptEditorSyntaxWorker(LLWorkerThread* thread, LLScriptEditor* editor) + : LLWorkerClass(thread, "ScriptEditorSyntax"), + mEditor(editor), + mHasPending(false), + mDropResults(false) + { + } + + void queueRequest(const Request& request) + { + bool should_add = false; + { + LLMutexLock lock(&mRequestMutex); + mPendingRequest = request; + mHasPending = true; + should_add = (!haveWork() && !isWorking()); + } + if (should_add) + { + addWork(0); + } + } + + void pump() + { + checkWork(); + bool should_add = false; + { + LLMutexLock lock(&mRequestMutex); + should_add = (!haveWork() && !isWorking() && mHasPending); + } + if (should_add) + { + addWork(0); + } + } + + void waitForIdle(bool drop_results) + { + mDropResults = drop_results; + { + LLMutexLock lock(&mRequestMutex); + mHasPending = false; + } + if (mRequestHandle != LLWorkerThread::nullHandle()) + { + mWorkerThread->waitForResult(mRequestHandle, false); + checkWork(); + } + mDropResults = false; + } + + void shutdown() + { + mEditor = nullptr; + waitForIdle(true); + scheduleDelete(); + } + +private: + void startWork(S32 param) override + { + LLMutexLock lock(&mRequestMutex); + if (!mHasPending) + { + return; + } + mActiveRequest = mPendingRequest; + mHasPending = false; + } + + bool doWork(S32 param) override + { + Request request; + { + LLMutexLock lock(&mRequestMutex); + request = mActiveRequest; + } + + Result result; + result.text = request.text; + result.text_generation = request.text_generation; + result.keywords_generation = request.keywords_generation; + result.disable_highlight = request.disable_highlight; + result.keywords = request.keywords; + + if (request.keywords) + { + request.keywords->collectSegmentOps(result.ops, request.text, request.disable_highlight); + } + + { + LLMutexLock lock(&mResultMutex); + mResult = std::move(result); + } + return true; + } + + void endWork(S32 param, bool aborted) override + { + if (aborted || mDropResults || !mEditor) + { + return; + } + + Result result; + { + LLMutexLock lock(&mResultMutex); + result = std::move(mResult); + } + + if (mEditor->getTextGeneration() != result.text_generation) + { + return; + } + if (mEditor->getKeywordsGeneration() != result.keywords_generation) + { + return; + } + if (&mEditor->getKeywords() != result.keywords) + { + return; + } + + mEditor->applySyntaxSegments(result.text, result.ops); + } + + LLScriptEditor* mEditor; + LLMutex mRequestMutex; + LLMutex mResultMutex; + Request mPendingRequest; + Request mActiveRequest; + Result mResult; + bool mHasPending; + bool mDropResults; +}; const S32 UI_TEXTEDITOR_LINE_NUMBER_MARGIN = 32; @@ -46,7 +213,13 @@ LLScriptEditor::LLScriptEditor(const Params& p) : LLTextEditor(p) , mShowLineNumbers(p.show_line_numbers), mUseDefaultFontSize(p.default_font_size), - mLuauLanguage(false) + mLuauLanguage(false), + mKeywordsGeneration(0), + mLastQueuedTextGeneration(-1), + mLastQueuedKeywordsGeneration(0), + mLastQueuedDisableHighlight(false), + mLastQueuedKeywords(nullptr), + mSyntaxWorker(nullptr) { if (mShowLineNumbers) { @@ -55,6 +228,16 @@ LLScriptEditor::LLScriptEditor(const Params& p) } } +LLScriptEditor::~LLScriptEditor() +{ + if (mSyntaxWorker) + { + mSyntaxWorker->shutdown(); + getSyntaxWorkerThread().update(0.f); + mSyntaxWorker = nullptr; + } +} + bool LLScriptEditor::postBuild() { gSavedSettings.getControl("LSLFontSizeName")->getCommitSignal()->connect(boost::bind(&LLScriptEditor::onFontSizeChange, this)); @@ -154,43 +337,93 @@ void LLScriptEditor::initKeywords(bool luau_language) void LLScriptEditor::loadKeywords() { LL_PROFILE_ZONE_SCOPED; + ensureSyntaxWorker(); + mSyntaxWorker->waitForIdle(true); getKeywords().processTokens(); + ++mKeywordsGeneration; - LLStyleConstSP style = new LLStyle(LLStyle::Params().font(getScriptFont()).color(mDefaultColor.get())); - - segment_vec_t segment_list; - getKeywords().findSegments(&segment_list, getWText(), *this, style); - - mSegments.clear(); - segment_set_t::iterator insert_it = mSegments.begin(); - for (segment_vec_t::iterator list_it = segment_list.begin(); list_it != segment_list.end(); ++list_it) + LLKeywords::segment_ops_t ops; + const LLWString& text = getWText(); + const llwchar* base = text.c_str(); + for (const llwchar* cur = base; *cur; ++cur) { - insert_it = mSegments.insert(insert_it, *list_it); + if (*cur == '\n') + { + ops.push_back({LLKeywords::SegmentOp::OP_LINE_BREAK, (S32)(cur - base), 0, nullptr}); + } } + applySyntaxSegments(text, ops); + queueSyntaxParse(); } void LLScriptEditor::updateSegments() { - if (mReflowIndex < S32_MAX && getKeywords().isLoaded() && mParseOnTheFly) + if (getKeywords().isLoaded() && mParseOnTheFly) { LL_PROFILE_ZONE_SCOPED; - - LLStyleConstSP style = new LLStyle(LLStyle::Params().font(getScriptFont()).color(mDefaultColor.get())); - - // HACK: No non-ascii keywords for now - segment_vec_t segment_list; - getKeywords().findSegments(&segment_list, getWText(), *this, style); - - clearSegments(); - for (segment_vec_t::iterator list_it = segment_list.begin(); list_it != segment_list.end(); ++list_it) + ensureSyntaxWorker(); + mSyntaxWorker->pump(); + if (mReflowIndex < S32_MAX) { - insertSegment(*list_it); + queueSyntaxParse(); } } LLTextBase::updateSegments(); } +void LLScriptEditor::ensureSyntaxWorker() +{ + if (!mSyntaxWorker) + { + mSyntaxWorker = new LLScriptEditorSyntaxWorker(&getSyntaxWorkerThread(), this); + } +} + +void LLScriptEditor::queueSyntaxParse() +{ + static LLCachedControl sDisableSyntaxHighlighting(gSavedSettings, "ScriptEditorDisableSyntaxHighlight", false); + const bool disable_syntax_highlighting = sDisableSyntaxHighlighting; + + LLKeywords* keywords = &getKeywords(); + const S32 text_generation = getTextGeneration(); + + if (mLastQueuedTextGeneration == text_generation + && mLastQueuedKeywordsGeneration == mKeywordsGeneration + && mLastQueuedDisableHighlight == disable_syntax_highlighting + && mLastQueuedKeywords == keywords) + { + return; + } + + mLastQueuedTextGeneration = text_generation; + mLastQueuedKeywordsGeneration = mKeywordsGeneration; + mLastQueuedDisableHighlight = disable_syntax_highlighting; + mLastQueuedKeywords = keywords; + + LLScriptEditorSyntaxWorker::Request request; + request.text = getWText(); + request.text_generation = text_generation; + request.keywords_generation = mKeywordsGeneration; + request.disable_highlight = disable_syntax_highlighting; + request.keywords = keywords; + mSyntaxWorker->queueRequest(request); +} + +void LLScriptEditor::applySyntaxSegments(const LLWString& text, const LLKeywords::segment_ops_t& ops) +{ + LLStyleConstSP style = new LLStyle(LLStyle::Params().font(getScriptFont()).color(mDefaultColor.get())); + + segment_vec_t segment_list; + getKeywords().applySegmentOps(&segment_list, text, ops, *this, style); + + clearSegments(); + for (segment_vec_t::iterator list_it = segment_list.begin(); list_it != segment_list.end(); ++list_it) + { + insertSegment(*list_it); + } +} + void LLScriptEditor::clearSegments() { if (!mSegments.empty()) diff --git a/indra/newview/llscripteditor.h b/indra/newview/llscripteditor.h index 2d98110f75..1ca26fbcc9 100644 --- a/indra/newview/llscripteditor.h +++ b/indra/newview/llscripteditor.h @@ -41,7 +41,7 @@ public: Params(); }; - ~LLScriptEditor() override {}; + ~LLScriptEditor() override; // LLView override void draw() override; @@ -55,6 +55,8 @@ public: LLKeywords& getKeywords(); bool getIsLuauLanguage() { return mLuauLanguage; } void setLuauLanguage(bool luau_language) { mLuauLanguage = luau_language; } + U32 getKeywordsGeneration() const { return mKeywordsGeneration; } + void applySyntaxSegments(const LLWString& text, const LLKeywords::segment_ops_t& ops); static std::string getScriptFontSize(); LLFontGL* getScriptFont(); @@ -68,6 +70,8 @@ private: void drawLineNumbers(); void updateSegments() override; void drawSelectionBackground() override; + void ensureSyntaxWorker(); + void queueSyntaxParse(); LLKeywords mKeywordsLua; LLKeywords mKeywordsLSL; @@ -75,6 +79,12 @@ private: bool mShowLineNumbers; bool mUseDefaultFontSize; + U32 mKeywordsGeneration; + S32 mLastQueuedTextGeneration; + U32 mLastQueuedKeywordsGeneration; + bool mLastQueuedDisableHighlight; + LLKeywords* mLastQueuedKeywords; + class LLScriptEditorSyntaxWorker* mSyntaxWorker; }; #endif // LL_SCRIPTEDITOR_H -- cgit v1.3 From bb56e9dd9ff4b93c910bd1d72fb6cdba31be3ea9 Mon Sep 17 00:00:00 2001 From: Andrey Lihatskiy Date: Mon, 12 Jan 2026 06:20:24 +0200 Subject: #5278 Async syntax apply in slices to avoid UI stalls --- indra/llui/llkeywords.cpp | 52 ++++++++++----- indra/llui/llkeywords.h | 8 +++ indra/newview/llscripteditor.cpp | 132 ++++++++++++++++++++++++++++++++++++++- indra/newview/llscripteditor.h | 28 +++++++++ 4 files changed, 204 insertions(+), 16 deletions(-) (limited to 'indra/newview/llscripteditor.cpp') diff --git a/indra/llui/llkeywords.cpp b/indra/llui/llkeywords.cpp index 0ada54df06..8c34e4ab9c 100644 --- a/indra/llui/llkeywords.cpp +++ b/indra/llui/llkeywords.cpp @@ -828,29 +828,41 @@ void LLKeywords::collectSegmentOps(segment_ops_t& ops, const LLWString& wtext, b } } -void LLKeywords::applySegmentOps(std::vector *seg_list, - const LLWString& wtext, - const segment_ops_t& ops, - LLTextEditor& editor, - LLStyleConstSP style) +bool LLKeywords::applySegmentOpsRange(std::vector *seg_list, + const LLWString& wtext, + const segment_ops_t& ops, + size_t& op_index, + size_t max_ops, + LLTextEditor& editor, + LLStyleConstSP style) { if (wtext.empty()) { - return; + return true; } - // Clear the segment list - seg_list->clear(); - // Reserve capacity for segments based on an estimated average of 8 characters per segment. - constexpr size_t AVERAGE_SEGMENT_LENGTH = 8; - seg_list->reserve(wtext.size() / AVERAGE_SEGMENT_LENGTH); + if (op_index == 0) + { + // Clear the segment list + seg_list->clear(); + // Reserve capacity for segments based on an estimated average of 8 characters per segment. + constexpr size_t AVERAGE_SEGMENT_LENGTH = 8; + seg_list->reserve(wtext.size() / AVERAGE_SEGMENT_LENGTH); - S32 text_len = static_cast(wtext.size()) + 1; + S32 text_len = static_cast(wtext.size()) + 1; + seg_list->push_back( new LLNormalTextSegment( style, 0, text_len, editor ) ); + } - seg_list->push_back( new LLNormalTextSegment( style, 0, text_len, editor ) ); + S32 text_len = static_cast(wtext.size()) + 1; + size_t end_index = op_index + max_ops; + if (end_index > ops.size()) + { + end_index = ops.size(); + } - for (const auto& op : ops) + for (; op_index < end_index; ++op_index) { + const auto& op = ops[op_index]; if (op.type == SegmentOp::OP_LINE_BREAK) { LLTextSegmentPtr text_segment = new LLLineBreakTextSegment(style, op.start); @@ -862,6 +874,18 @@ void LLKeywords::applySegmentOps(std::vector *seg_list, insertSegments(wtext, *seg_list, op.token, text_len, op.start, op.end, style, editor); } } + + return op_index >= ops.size(); +} + +void LLKeywords::applySegmentOps(std::vector *seg_list, + const LLWString& wtext, + const segment_ops_t& ops, + LLTextEditor& editor, + LLStyleConstSP style) +{ + size_t op_index = 0; + applySegmentOpsRange(seg_list, wtext, ops, op_index, ops.size(), editor, style); } // Walk through a string, applying the rules specified by the keyword token list and diff --git a/indra/llui/llkeywords.h b/indra/llui/llkeywords.h index b8689a0e88..70fc2c20d5 100644 --- a/indra/llui/llkeywords.h +++ b/indra/llui/llkeywords.h @@ -37,6 +37,7 @@ #include #include #include +#include #include "llpointer.h" class LLTextSegment; @@ -144,6 +145,13 @@ public: const segment_ops_t& ops, class LLTextEditor& editor, LLStyleConstSP style); + bool applySegmentOpsRange(std::vector *seg_list, + const LLWString& text, + const segment_ops_t& ops, + size_t& op_index, + size_t max_ops, + class LLTextEditor& editor, + LLStyleConstSP style); void initialize(LLSD SyntaxXML, bool luau_language = false); void processTokens(); diff --git a/indra/newview/llscripteditor.cpp b/indra/newview/llscripteditor.cpp index 871210ea6d..93244107ca 100644 --- a/indra/newview/llscripteditor.cpp +++ b/indra/newview/llscripteditor.cpp @@ -32,6 +32,7 @@ #include "lllocalcliprect.h" #include "llviewercontrol.h" #include "llworkerthread.h" +#include #include static LLWorkerThread& getSyntaxWorkerThread() @@ -186,7 +187,12 @@ private: return; } - mEditor->applySyntaxSegments(result.text, result.ops); + mEditor->queueSyntaxApply(std::move(result.text), + std::move(result.ops), + result.text_generation, + result.keywords_generation, + result.disable_highlight, + result.keywords); } LLScriptEditor* mEditor; @@ -219,7 +225,14 @@ LLScriptEditor::LLScriptEditor(const Params& p) mLastQueuedKeywordsGeneration(0), mLastQueuedDisableHighlight(false), mLastQueuedKeywords(nullptr), - mSyntaxWorker(nullptr) + mSyntaxWorker(nullptr), + mSyntaxApplyState(SyntaxApplyState::Idle), + mPendingApplyOpIndex(0), + mPendingApplySegmentIndex(0), + mPendingApplyTextGeneration(-1), + mPendingApplyKeywordsGeneration(0), + mPendingApplyDisableHighlight(false), + mPendingApplyKeywords(nullptr) { if (mShowLineNumbers) { @@ -339,6 +352,7 @@ void LLScriptEditor::loadKeywords() LL_PROFILE_ZONE_SCOPED; ensureSyntaxWorker(); mSyntaxWorker->waitForIdle(true); + resetPendingSyntaxApply(); getKeywords().processTokens(); ++mKeywordsGeneration; @@ -367,6 +381,7 @@ void LLScriptEditor::updateSegments() { queueSyntaxParse(); } + processPendingSyntaxApply(); } LLTextBase::updateSegments(); @@ -410,6 +425,119 @@ void LLScriptEditor::queueSyntaxParse() mSyntaxWorker->queueRequest(request); } +void LLScriptEditor::queueSyntaxApply(LLWString text, + LLKeywords::segment_ops_t ops, + S32 text_generation, + U32 keywords_generation, + bool disable_highlight, + LLKeywords* keywords) +{ + if (text_generation != getTextGeneration() + || keywords_generation != mKeywordsGeneration + || keywords != &getKeywords()) + { + return; + } + + resetPendingSyntaxApply(); + + constexpr size_t kImmediateOpsThreshold = 500; + if (ops.size() <= kImmediateOpsThreshold) + { + applySyntaxSegments(text, ops); + return; + } + + mPendingApplyText = std::move(text); + mPendingApplyOps = std::move(ops); + mPendingApplyTextGeneration = text_generation; + mPendingApplyKeywordsGeneration = keywords_generation; + mPendingApplyDisableHighlight = disable_highlight; + mPendingApplyKeywords = keywords; + mPendingApplyOpIndex = 0; + mPendingApplySegmentIndex = 0; + mPendingApplySegments.clear(); + mPendingApplySegmentSet.clear(); + mPendingApplyStyle = new LLStyle(LLStyle::Params().font(getScriptFont()).color(mDefaultColor.get())); + mSyntaxApplyState = SyntaxApplyState::Building; +} + +void LLScriptEditor::processPendingSyntaxApply() +{ + if (mSyntaxApplyState == SyntaxApplyState::Idle) + { + return; + } + + static LLCachedControl sDisableSyntaxHighlighting(gSavedSettings, "ScriptEditorDisableSyntaxHighlight", false); + if (mPendingApplyTextGeneration != getTextGeneration() + || mPendingApplyKeywordsGeneration != mKeywordsGeneration + || mPendingApplyKeywords != &getKeywords() + || mPendingApplyDisableHighlight != sDisableSyntaxHighlighting) + { + resetPendingSyntaxApply(); + return; + } + + constexpr size_t kOpsPerSlice = 250; + constexpr size_t kSegmentsPerSlice = 250; + + if (mSyntaxApplyState == SyntaxApplyState::Building) + { + if (mPendingApplyStyle.isNull()) + { + mPendingApplyStyle = new LLStyle(LLStyle::Params().font(getScriptFont()).color(mDefaultColor.get())); + } + bool done = getKeywords().applySegmentOpsRange(&mPendingApplySegments, + mPendingApplyText, + mPendingApplyOps, + mPendingApplyOpIndex, + kOpsPerSlice, + *this, + mPendingApplyStyle); + if (done) + { + mSyntaxApplyState = SyntaxApplyState::Inserting; + } + return; + } + + size_t end_index = std::min(mPendingApplySegmentIndex + kSegmentsPerSlice, mPendingApplySegments.size()); + for (; mPendingApplySegmentIndex < end_index; ++mPendingApplySegmentIndex) + { + LLTextSegmentPtr segment = mPendingApplySegments[mPendingApplySegmentIndex]; + segment->linkToDocument(this); + mPendingApplySegmentSet.insert(segment); + } + + if (mPendingApplySegmentIndex >= mPendingApplySegments.size()) + { + S32 saved_scroll_index = mScrollIndex; + segment_set_t old_segments; + old_segments.swap(mSegments); + mSegments.swap(mPendingApplySegmentSet); + mScrollIndex = saved_scroll_index; + needsReflow(0); + resetPendingSyntaxApply(); + } +} + +void LLScriptEditor::resetPendingSyntaxApply() +{ + mSyntaxApplyState = SyntaxApplyState::Idle; + mPendingApplyText.clear(); + mPendingApplyOps.clear(); + mPendingApplySegments.clear(); + mPendingApplySegmentSet.clear(); + mPendingApplyOpIndex = 0; + mPendingApplySegmentIndex = 0; + mPendingApplyStyle = LLStyleConstSP(); + mPendingApplyTextGeneration = -1; + mPendingApplyKeywordsGeneration = 0; + mPendingApplyDisableHighlight = false; + mPendingApplyKeywords = nullptr; +} + void LLScriptEditor::applySyntaxSegments(const LLWString& text, const LLKeywords::segment_ops_t& ops) { LLStyleConstSP style = new LLStyle(LLStyle::Params().font(getScriptFont()).color(mDefaultColor.get())); diff --git a/indra/newview/llscripteditor.h b/indra/newview/llscripteditor.h index 1ca26fbcc9..dcbfdf3085 100644 --- a/indra/newview/llscripteditor.h +++ b/indra/newview/llscripteditor.h @@ -29,6 +29,7 @@ #define LL_SCRIPTEDITOR_H #include "lltexteditor.h" +#include class LLScriptEditor : public LLTextEditor { @@ -64,14 +65,29 @@ public: protected: friend class LLUICtrlFactory; + friend class LLScriptEditorSyntaxWorker; LLScriptEditor(const Params& p); private: + enum class SyntaxApplyState + { + Idle, + Building, + Inserting + }; void drawLineNumbers(); void updateSegments() override; void drawSelectionBackground() override; void ensureSyntaxWorker(); void queueSyntaxParse(); + void queueSyntaxApply(LLWString text, + LLKeywords::segment_ops_t ops, + S32 text_generation, + U32 keywords_generation, + bool disable_highlight, + LLKeywords* keywords); + void processPendingSyntaxApply(); + void resetPendingSyntaxApply(); LLKeywords mKeywordsLua; LLKeywords mKeywordsLSL; @@ -85,6 +101,18 @@ private: bool mLastQueuedDisableHighlight; LLKeywords* mLastQueuedKeywords; class LLScriptEditorSyntaxWorker* mSyntaxWorker; + SyntaxApplyState mSyntaxApplyState; + LLWString mPendingApplyText; + LLKeywords::segment_ops_t mPendingApplyOps; + segment_vec_t mPendingApplySegments; + segment_set_t mPendingApplySegmentSet; + size_t mPendingApplyOpIndex; + size_t mPendingApplySegmentIndex; + LLStyleConstSP mPendingApplyStyle; + S32 mPendingApplyTextGeneration; + U32 mPendingApplyKeywordsGeneration; + bool mPendingApplyDisableHighlight; + LLKeywords* mPendingApplyKeywords; }; #endif // LL_SCRIPTEDITOR_H -- cgit v1.3 From f1f89b2a21468a9a6f90bfd77a5dfcbcb0b3c0c6 Mon Sep 17 00:00:00 2001 From: Andrey Lihatskiy Date: Mon, 12 Jan 2026 06:42:56 +0200 Subject: #5278 Use correct font for unhighlighted segments --- indra/newview/llscripteditor.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'indra/newview/llscripteditor.cpp') diff --git a/indra/newview/llscripteditor.cpp b/indra/newview/llscripteditor.cpp index 93244107ca..68c4077b89 100644 --- a/indra/newview/llscripteditor.cpp +++ b/indra/newview/llscripteditor.cpp @@ -254,7 +254,9 @@ LLScriptEditor::~LLScriptEditor() bool LLScriptEditor::postBuild() { gSavedSettings.getControl("LSLFontSizeName")->getCommitSignal()->connect(boost::bind(&LLScriptEditor::onFontSizeChange, this)); - return LLTextEditor::postBuild(); + bool result = LLTextEditor::postBuild(); + setFont(getScriptFont()); + return result; } void LLScriptEditor::draw() @@ -621,6 +623,7 @@ void LLScriptEditor::onFontSizeChange() { if (!mUseDefaultFontSize) { + setFont(getScriptFont()); needsReflow(); } } -- cgit v1.3 From 04db46f0b12c894983fdb1bb783fbad9d5a11943 Mon Sep 17 00:00:00 2001 From: Andrey Lihatskiy Date: Thu, 15 Jan 2026 06:24:41 +0200 Subject: #5278 Reduce reallocs --- indra/llui/llkeywords.cpp | 2 ++ indra/newview/llscripteditor.cpp | 2 ++ 2 files changed, 4 insertions(+) (limited to 'indra/newview/llscripteditor.cpp') diff --git a/indra/llui/llkeywords.cpp b/indra/llui/llkeywords.cpp index bbcb45f100..c4272401b9 100644 --- a/indra/llui/llkeywords.cpp +++ b/indra/llui/llkeywords.cpp @@ -506,6 +506,8 @@ void LLKeywords::collectSegmentOps(segment_ops_t& ops, const LLWString& wtext, b { return; } + // Heuristic to reduce reallocation churn on large scripts. + ops.reserve(wtext.size() / 8); const llwchar* base = wtext.c_str(); const llwchar* cur = base; diff --git a/indra/newview/llscripteditor.cpp b/indra/newview/llscripteditor.cpp index 68c4077b89..2a4c2b9d0b 100644 --- a/indra/newview/llscripteditor.cpp +++ b/indra/newview/llscripteditor.cpp @@ -443,6 +443,7 @@ void LLScriptEditor::queueSyntaxApply(LLWString text, resetPendingSyntaxApply(); + // Small updates can apply synchronously; larger ones use background slices. constexpr size_t kImmediateOpsThreshold = 500; if (ops.size() <= kImmediateOpsThreshold) { @@ -481,6 +482,7 @@ void LLScriptEditor::processPendingSyntaxApply() return; } + // Slice sizes control UI budget while applying large highlight updates. constexpr size_t kOpsPerSlice = 250; constexpr size_t kSegmentsPerSlice = 250; -- cgit v1.3