perf(addon-search): avoid repeated substring allocation in reverse regex

Hoist searchStringLine.slice(0, offset) outside the reverse regex exec loop.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Daniel Imms
2026-05-25 17:40:31 -07:00
co-authored by Cursor
parent c7baa96f97
commit 9902f54c93
+2 -1
View File
@@ -288,7 +288,8 @@ export class SearchEngine {
let foundTerm: RegExpExecArray | null;
if (isReverseSearch) {
// This loop will get the resultIndex of the _last_ regex match in the range 0..offset
while (foundTerm = searchRegex.exec(searchStringLine.slice(0, offset))) {
const searchSubstring = searchStringLine.slice(0, offset);
while (foundTerm = searchRegex.exec(searchSubstring)) {
if (foundTerm[0].length === 0) {
continue;
}