From 265fe750a892d8b7fc8090f4b53048915489336f Mon Sep 17 00:00:00 2001 From: ajreckof <66184050+ajreckof@users.noreply.github.com> Date: Thu, 10 Aug 2023 07:47:52 +0200 Subject: [PATCH] Fix CodeEdit completion being very slow in certain cases (cherry picked from commit 1eb3d99ff78932a7105ef0873056644db4598040) --- scene/gui/code_edit.cpp | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/scene/gui/code_edit.cpp b/scene/gui/code_edit.cpp index 1944b8db989..6f9dc51cfb6 100644 --- a/scene/gui/code_edit.cpp +++ b/scene/gui/code_edit.cpp @@ -3123,6 +3123,7 @@ void CodeEdit::_filter_code_completion_candidates_impl() { } String target_lower = option.display.to_lower(); + int long_option = target_lower.size() > 50; const char32_t *string_to_complete_char_lower = &string_to_complete_lower[0]; const char32_t *target_char_lower = &target_lower[0]; @@ -3137,27 +3138,34 @@ void CodeEdit::_filter_code_completion_candidates_impl() { for (int i = 1; *string_to_complete_char_lower && (all_possible_subsequence_matches.size() > 0); i++, string_to_complete_char_lower++) { // find all occurrences of ssq_lower to avoid looking everywhere each time Vector all_ocurence; - for (int j = i; j < target_lower.length(); j++) { - if (target_lower[j] == *string_to_complete_char_lower) { - all_ocurence.push_back(j); + if (long_option) { + all_ocurence.push_back(target_lower.find_char(*string_to_complete_char_lower)); + } else { + for (int j = i; j < target_lower.length(); j++) { + if (target_lower[j] == *string_to_complete_char_lower) { + all_ocurence.push_back(j); + } } } Vector>> next_subsequence_matches; - for (Vector> &subsequence_matches : all_possible_subsequence_matches) { - Pair match_last_segment = subsequence_matches[subsequence_matches.size() - 1]; + for (Vector> &subsequence_match : all_possible_subsequence_matches) { + Pair match_last_segment = subsequence_match[subsequence_match.size() - 1]; int next_index = match_last_segment.first + match_last_segment.second; // get the last index from current sequence // and look for next char starting from that index if (target_lower[next_index] == *string_to_complete_char_lower) { - Vector> new_matches = subsequence_matches; - new_matches.write[new_matches.size() - 1].second++; - next_subsequence_matches.push_back(new_matches); + Vector> new_match = subsequence_match; + new_match.write[new_match.size() - 1].second++; + next_subsequence_matches.push_back(new_match); + if (long_option) { + continue; + } } for (int index : all_ocurence) { if (index > next_index) { - Vector> new_matches = subsequence_matches; - new_matches.push_back({ index, 1 }); - next_subsequence_matches.push_back(new_matches); + Vector> new_match = subsequence_match; + new_match.push_back({ index, 1 }); + next_subsequence_matches.push_back(new_match); } } }