提交 0c25f5a7 编写于 作者: J Johannes Rieken

early check for strong first matches, helps with https://github.com/microsoft/vscode/issues/91807

上级 84ed4b54
......@@ -559,6 +559,8 @@ export function fuzzyScore(pattern: string, patternLow: string, patternStart: nu
let patternPos = patternStart;
let wordPos = wordStart;
let hasStrongFirstMatch = false;
// There will be a match, fill in tables
for (row = 1, patternPos = patternStart; patternPos < patternLen; row++, patternPos++) {
......@@ -566,6 +568,10 @@ export function fuzzyScore(pattern: string, patternLow: string, patternStart: nu
const score = _doScore(pattern, patternLow, patternPos, patternStart, word, wordLow, wordPos);
if (patternPos === patternStart && score > 1) {
hasStrongFirstMatch = true;
}
_scores[row][column] = score;
const diag = _table[row - 1][column - 1] + (score > 1 ? 1 : score);
......@@ -604,6 +610,10 @@ export function fuzzyScore(pattern: string, patternLow: string, patternStart: nu
printTables(pattern, patternStart, word, wordStart);
}
if (!hasStrongFirstMatch && !firstMatchCanBeWeak) {
return undefined;
}
_matchesCount = 0;
_topScore = -100;
_wordStart = wordStart;
......
......@@ -343,6 +343,36 @@ suite('Filters', () => {
);
});
test('Freeze when fjfj -> jfjf, https://github.com/microsoft/vscode/issues/91807', function () {
assertMatches(
'jfjfj',
'fjfjfjfjfjfjfjfjfjfjfj',
undefined, fuzzyScore
);
assertMatches(
'jfjfjfjfjfjfjfjfjfj',
'fjfjfjfjfjfjfjfjfjfjfjfjfjfjfjfjfjfjfjfjfjfjfjfjfjfjfjfjfjfj',
undefined, fuzzyScore
);
assertMatches(
'jfjfjfjfjfjfjfjfjfjjfjfjfjfjfjfjfjfjfjjfjfjfjfjfjfjfjfjfjjfjfjfjfjfjfjfjfjfjjfjfjfjfjfjfjfjfjfjjfjfjfjfjfjfjfjfjfj',
'fjfjfjfjfjfjfjfjfjfjfjfjfjfjfjfjfjfjfjfjfjfjfjfjfjfjfjfjfjfjfjfjfjfjfjfjfjfjfjfjfjfjfjfjfjfjfjfjfjfjfjfjfjfjfjfjfjfjfjfj',
undefined, fuzzyScore
);
assertMatches(
'jfjfjfjfjfjfjfjfjfj',
'fJfjfjfjfjfjfjfjfjfjfjfjfjfjfjfjfjfjfjfjfjfjfjfjfjfjfjfjfjfj',
'f^J^f^j^f^j^f^j^f^j^f^j^f^j^f^j^f^j^f^jfjfjfjfjfjfjfjfjfjfjfjfjfjfjfjfjfjfjfjfj', // strong match
fuzzyScore
);
assertMatches(
'jfjfjfjfjfjfjfjfjfj',
'fjfjfjfjfjfjfjfjfjfjfjfjfjfjfjfjfjfjfjfjfjfjfjfjfjfjfjfjfjfj',
'f^j^f^j^f^j^f^j^f^j^f^j^f^j^f^j^f^j^f^jfjfjfjfjfjfjfjfjfjfjfjfjfjfjfjfjfjfjfjfj', // any match
fuzzyScore, { firstMatchCanBeWeak: true }
);
});
test('fuzzyScore, issue #26423', function () {
assertMatches('baba', 'abababab', undefined, fuzzyScore);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册