Skip to content

Commit 73d7b08

Browse files
committed
don't search for nothing, fixes microsoft#26423
1 parent 6e3427b commit 73d7b08

2 files changed

Lines changed: 25 additions & 0 deletions

File tree

src/vs/base/common/filters.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,9 @@ export function fuzzyScore(pattern: string, word: string): [number, number[]] {
478478
return undefined;
479479
}
480480

481+
// keep track of the maximum score
482+
let maxScore = -1;
483+
481484
for (i = 1; i <= patternLen; i++) {
482485

483486
let lastLowWordChar = '';
@@ -509,6 +512,9 @@ export function fuzzyScore(pattern: string, word: string): [number, number[]] {
509512
}
510513

511514
_scores[i][j] = score;
515+
if (score > maxScore) {
516+
maxScore = score;
517+
}
512518

513519
let diag = _table[i - 1][j - 1] + (score > 1 ? 1 : score);
514520
let top = _table[i - 1][j] + -1;
@@ -544,6 +550,10 @@ export function fuzzyScore(pattern: string, word: string): [number, number[]] {
544550
}
545551
}
546552

553+
if (maxScore <= 1) {
554+
return undefined;
555+
}
556+
547557
if (_debug) {
548558
console.log(printTable(_table, pattern, patternLen, word, wordLen));
549559
console.log(printTable(_arrows, pattern, patternLen, word, wordLen));

src/vs/base/test/common/filters.test.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,21 @@ suite('Filters', () => {
305305
);
306306
});
307307

308+
test('fuzzyScore, issue #26423', function () {
309+
assertMatches(
310+
'fsfsfs',
311+
'dsafdsafdsafdsafdsafdsafdsafasdfdsa',
312+
undefined,
313+
fuzzyScore
314+
);
315+
assertMatches(
316+
'fsfsfsfsfsfsfsf',
317+
'dsafdsafdsafdsafdsafdsafdsafasdfdsafdsafdsafdsafdsfdsafdsfdfdfasdnfdsajfndsjnafjndsajlknfdsa',
318+
undefined,
319+
fuzzyScore
320+
);
321+
});
322+
308323
function assertTopScore(filter: typeof fuzzyScore, pattern: string, expected: number, ...words: string[]) {
309324
let topScore = -(100 * 10);
310325
let topIdx = 0;

0 commit comments

Comments
 (0)