mirror of
https://github.com/stablyai/orca.git
synced 2026-09-22 16:02:32 +00:00
perf(cmd-j): scan phrase word boundaries monotonically (#20282)
This commit is contained in:
@@ -34,10 +34,23 @@ function phrasePlacement(field: PaletteIndexedField, normalizedQuery: string): n
|
||||
if (text.startsWith(normalizedQuery)) {
|
||||
return 0
|
||||
}
|
||||
for (const word of field.words) {
|
||||
if (text.startsWith(normalizedQuery, word.start)) {
|
||||
// Merge the ordered occurrence and word-start streams: occurrences only count at word
|
||||
// starts, so each side advances monotonically and never rescans the other.
|
||||
let index = text.indexOf(normalizedQuery, 1)
|
||||
let wordIndex = 0
|
||||
while (index !== -1) {
|
||||
let wordStart = field.words[wordIndex]?.start
|
||||
while (wordStart !== undefined && wordStart < index) {
|
||||
wordIndex += 1
|
||||
wordStart = field.words[wordIndex]?.start
|
||||
}
|
||||
if (wordStart === undefined) {
|
||||
break
|
||||
}
|
||||
if (wordStart === index) {
|
||||
return 1
|
||||
}
|
||||
index = text.indexOf(normalizedQuery, wordStart)
|
||||
}
|
||||
return 2
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user