Skip to content

Commit 948bc12

Browse files
authored
stop early when there are no candidate hats for a grapheme (#1692)
No functional changes. However it prevents a bunch of pointless runs through the scoring functions with an empty set of candidates. (All the early stopping conditions check for a unique winner, not the empty set. Those aren't worth changing, when we can trivially avoid calling the function at all.) The main benefit is reduced noise when logging inside the scoring functions when debugging. ## Checklist - [/] I have added [tests](https://www.cursorless.org/docs/contributing/test-case-recorder/) - [/] I have updated the [docs](https://github.com/cursorless-dev/cursorless/tree/main/docs) and [cheatsheet](https://github.com/cursorless-dev/cursorless/tree/main/cursorless-talon/src/cheatsheet) - [/] I have not broken the cheatsheet
1 parent 77a34ab commit 948bc12

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

packages/cursorless-engine/src/util/allocateHats/maxByFirstDiffering.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ export function maxByFirstDiffering<T>(
2020
arr: T[],
2121
fns: ((item: T) => number)[],
2222
): T | undefined {
23+
if (arr.length === 0) {
24+
return undefined;
25+
}
2326
let remainingValues = arr;
2427

2528
for (const fn of fns) {

0 commit comments

Comments
 (0)