Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
eb34efe9
V
vscode
项目概览
xxadev
/
vscode
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
V
vscode
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
eb34efe9
编写于
3月 13, 2017
作者:
J
Johannes Rieken
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fuzzMatch3, more perf
上级
4afa2dfe
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
160 addition
and
5 deletion
+160
-5
src/vs/base/common/filters.ts
src/vs/base/common/filters.ts
+87
-0
src/vs/base/test/common/filters.perf.test.ts
src/vs/base/test/common/filters.perf.test.ts
+40
-4
src/vs/base/test/common/filters.test.ts
src/vs/base/test/common/filters.test.ts
+33
-1
未找到文件。
src/vs/base/common/filters.ts
浏览文件 @
eb34efe9
...
...
@@ -383,3 +383,90 @@ export function matchesFuzzy2(pattern: string, word: string): IMatch[] | undefin
return
result
.
length
>
0
?
result
:
undefined
;
}
export
function
matchesFuzzy3
(
pattern
:
string
,
word
:
string
)
{
return
_doMatchesFuzzy3
(
pattern
,
pattern
.
toLowerCase
(),
0
,
word
,
word
.
toLowerCase
(),
0
,
[],
0
);
}
function
_doMatchesFuzzy3
(
pattern
:
string
,
lowPattern
:
string
,
patternPos
:
number
,
word
:
string
,
lowWord
:
string
,
wordPos
:
number
,
positions
:
number
[],
score
:
number
):
[
IMatch
[],
number
]
{
let
retryPoints
:
number
[]
=
[];
let
lastDidMatch
=
false
;
while
(
patternPos
<
lowPattern
.
length
&&
wordPos
<
lowWord
.
length
)
{
const
charLowPattern
=
lowPattern
.
charAt
(
patternPos
);
const
charLowWord
=
lowWord
.
charAt
(
wordPos
);
if
(
charLowPattern
===
charLowWord
)
{
if
(
positions
.
length
===
0
)
{
score
=
-
Math
.
min
(
wordPos
,
3
)
*
3
;
// penalty -> gaps at start
}
else
if
(
lastDidMatch
)
{
score
+=
1
;
// bonus -> subsequent match
}
if
(
charLowWord
!==
word
.
charAt
(
wordPos
))
{
score
+=
10
;
// bonus -> upper-case
}
else
if
(
wordPos
>
0
&&
word
.
charAt
(
wordPos
).
match
(
_separator
))
{
score
+=
10
;
// bonus -> after a separator
}
else
{
// keep this as a retry point
retryPoints
.
push
(
patternPos
,
wordPos
+
1
,
positions
.
length
,
score
);
}
patternPos
+=
1
;
positions
.
push
(
wordPos
);
lastDidMatch
=
true
;
}
else
{
lastDidMatch
=
false
;
score
-=
1
;
// penalty -> gaps in match
}
wordPos
+=
1
;
}
if
(
positions
.
length
===
0
)
{
return
undefined
;
}
const
matches
:
IMatch
[]
=
[];
let
lastMatch
:
IMatch
;
for
(
const
pos
of
positions
)
{
if
(
lastMatch
&&
lastMatch
.
end
===
pos
)
{
lastMatch
.
end
+=
1
;
}
else
{
lastMatch
=
{
start
:
pos
,
end
:
pos
+
1
};
matches
.
push
(
lastMatch
);
}
}
let
result
:
[
IMatch
[],
number
]
=
[
matches
,
score
];
// try alternative matches
for
(
let
i
=
0
;
i
<
retryPoints
.
length
;
i
+=
4
)
{
const
alt
=
_doMatchesFuzzy3
(
pattern
,
lowPattern
,
retryPoints
[
i
],
word
,
lowWord
,
retryPoints
[
i
+
1
],
positions
.
slice
(
0
,
retryPoints
[
i
+
2
]),
retryPoints
[
i
+
3
]
);
if
(
alt
&&
alt
[
1
]
>
result
[
1
])
{
result
=
alt
;
}
}
return
result
;
}
const
_separator
=
/
[
-_.
]
/
;
src/vs/base/test/common/filters.perf.test.ts
浏览文件 @
eb34efe9
...
...
@@ -5,10 +5,11 @@
'
use strict
'
;
import
*
as
assert
from
'
assert
'
;
import
{
fuzzyContiguousFilter
,
matchesFuzzy2
}
from
'
vs/base/common/filters
'
;
import
{
fuzzyContiguousFilter
,
matchesFuzzy2
,
matchesFuzzy3
}
from
'
vs/base/common/filters
'
;
const
fuzz
=
require
.
__$__nodeRequire
(
'
fuzzaldrin-plus
'
);
const
data
=
<
{
label
:
string
}[]
>
require
.
__$__nodeRequire
(
require
.
toUrl
(
'
./filters.perf.data.json
'
));
const
patterns
=
[
'
cci
'
,
'
CCI
'
,
'
ida
'
,
'
pos
'
,
'
enbled
'
,
'
callback
'
,
'
gGame
'
];
const
patterns
=
[
'
cci
'
,
'
ida
'
,
'
pos
'
,
'
CCI
'
,
'
enbled
'
,
'
callback
'
,
'
gGame
'
];
const
_enablePerf
=
true
;
...
...
@@ -35,7 +36,7 @@ perfSuite('Performance - fuzzyMatch', function () {
}
}
}
console
.
log
(
Date
.
now
()
-
t1
,
count
);
console
.
log
(
Date
.
now
()
-
t1
,
count
,
(
count
/
(
Date
.
now
()
-
t1
)).
toPrecision
(
5
)
);
assert
.
ok
(
count
>
0
);
});
...
...
@@ -52,7 +53,42 @@ perfSuite('Performance - fuzzyMatch', function () {
}
}
}
console
.
log
(
Date
.
now
()
-
t1
,
count
);
console
.
log
(
Date
.
now
()
-
t1
,
count
,
(
count
/
(
Date
.
now
()
-
t1
)).
toPrecision
(
5
));
assert
.
ok
(
count
>
0
);
});
test
(
'
matchesFuzzy3
'
,
function
()
{
const
t1
=
Date
.
now
();
let
count
=
0
;
for
(
const
pattern
of
patterns
)
{
for
(
const
item
of
data
)
{
if
(
item
.
label
)
{
const
matches
=
matchesFuzzy3
(
pattern
,
item
.
label
);
if
(
matches
)
{
count
+=
1
;
}
}
}
}
console
.
log
(
Date
.
now
()
-
t1
,
count
,
(
count
/
(
Date
.
now
()
-
t1
)).
toPrecision
(
5
));
assert
.
ok
(
count
>
0
);
});
test
(
'
fuzzaldrin
'
,
function
()
{
const
t1
=
Date
.
now
();
let
count
=
0
;
for
(
const
pattern
of
patterns
)
{
for
(
const
item
of
data
)
{
if
(
item
.
label
)
{
const
matches
=
fuzz
.
match
(
item
.
label
,
pattern
);
// fuzz.score(item.label, pattern);
if
(
matches
)
{
count
+=
1
;
}
}
}
}
console
.
log
(
Date
.
now
()
-
t1
,
count
,
(
count
/
(
Date
.
now
()
-
t1
)).
toPrecision
(
5
));
assert
.
ok
(
count
>
0
);
});
});
...
...
src/vs/base/test/common/filters.test.ts
浏览文件 @
eb34efe9
...
...
@@ -5,7 +5,7 @@
'
use strict
'
;
import
*
as
assert
from
'
assert
'
;
import
{
IFilter
,
or
,
matchesPrefix
,
matchesStrictPrefix
,
matchesCamelCase
,
matchesSubString
,
matchesContiguousSubString
,
matchesWords
}
from
'
vs/base/common/filters
'
;
import
{
IFilter
,
or
,
matchesPrefix
,
matchesStrictPrefix
,
matchesCamelCase
,
matchesSubString
,
matchesContiguousSubString
,
matchesWords
,
matchesFuzzy3
}
from
'
vs/base/common/filters
'
;
function
filterOk
(
filter
:
IFilter
,
word
:
string
,
wordToMatchAgainst
:
string
,
highlights
?:
{
start
:
number
;
end
:
number
;
}[])
{
let
r
=
filter
(
word
,
wordToMatchAgainst
);
...
...
@@ -192,4 +192,36 @@ suite('Filters', () => {
assert
.
ok
(
matchesWords
(
'
gipu
'
,
'
Category: Git: Pull
'
,
true
)
===
null
);
assert
.
deepEqual
(
matchesWords
(
'
pu
'
,
'
Category: Git: Pull
'
,
true
),
[{
start
:
15
,
end
:
17
}]);
});
test
(
'
FuzzyMatchAndScore
'
,
function
()
{
// function toString(word: string, matches: IMatch[], score: number) {
// let underline = '';
// let lastEnd = 0;
// for (const { start, end } of matches) {
// underline += new Array(1 + start - lastEnd).join(' ');
// underline += new Array(1 + end - start).join('^');
// lastEnd = end;
// }
// return `${word} (score: ${score})\n${underline}`;
// }
let
[
matches
]
=
matchesFuzzy3
(
'
LLL
'
,
'
SVisualLoggerLogsList
'
);
assert
.
deepEqual
(
matches
,
[{
start
:
7
,
end
:
8
},
{
start
:
13
,
end
:
14
},
{
start
:
17
,
end
:
18
}]);
[
matches
]
=
matchesFuzzy3
(
'
foobar
'
,
'
foobar
'
);
assert
.
deepEqual
(
matches
,
[{
start
:
0
,
end
:
6
}]);
[
matches
]
=
matchesFuzzy3
(
'
tk
'
,
'
The Black Knight
'
);
assert
.
deepEqual
(
matches
,
[{
start
:
0
,
end
:
1
},
{
start
:
10
,
end
:
11
}]);
[
matches
]
=
matchesFuzzy3
(
'
Cat
'
,
'
charAt
'
);
assert
.
deepEqual
(
matches
,
[{
start
:
0
,
end
:
1
},
{
start
:
4
,
end
:
6
}]);
[
matches
]
=
matchesFuzzy3
(
'
Cat
'
,
'
charCodeAt
'
);
assert
.
deepEqual
(
matches
,
[{
start
:
4
,
end
:
5
},
{
start
:
8
,
end
:
10
}]);
[
matches
]
=
matchesFuzzy3
(
'
Cat
'
,
'
concat
'
);
assert
.
deepEqual
(
matches
,
[{
start
:
0
,
end
:
1
},
{
start
:
4
,
end
:
6
}]);
});
});
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录