From 70dad7e5a341f9cbd51509d46d0376d7a2d0e497 Mon Sep 17 00:00:00 2001 From: jsjtxietian Date: Sun, 20 Aug 2023 16:49:16 +0800 Subject: [PATCH] Fixes a text find perf issue, if can't find any match words, just early break the while loop. This will improve a lot when p_search.length is way too long since p_from_column will only plus 1 every loop --- scene/gui/text_edit.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp index 4a82f6e7259..cffd9604f6e 100644 --- a/scene/gui/text_edit.cpp +++ b/scene/gui/text_edit.cpp @@ -7000,6 +7000,11 @@ int TextEdit::_get_column_pos_of_word(const String &p_key, const String &p_searc col = p_search.findn(p_key, p_from_column); } + // If not found, just break early to improve performance. + if (col == -1) { + break; + } + // Whole words only. if (col != -1 && p_search_flags & SEARCH_WHOLE_WORDS) { p_from_column = col;