Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
4c83c567
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,发现更多精彩内容 >>
提交
4c83c567
编写于
7月 22, 2016
作者:
C
chrmarti
提交者:
GitHub
7月 22, 2016
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
#55: Improve result sorting performance (#9602)
上级
2cc6141e
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
51 addition
and
29 deletion
+51
-29
src/vs/base/common/arrays.ts
src/vs/base/common/arrays.ts
+23
-0
src/vs/base/common/comparers.ts
src/vs/base/common/comparers.ts
+2
-2
src/vs/base/test/common/arrays.test.ts
src/vs/base/test/common/arrays.test.ts
+12
-0
src/vs/workbench/parts/search/browser/openAnythingHandler.ts
src/vs/workbench/parts/search/browser/openAnythingHandler.ts
+14
-27
未找到文件。
src/vs/base/common/arrays.ts
浏览文件 @
4c83c567
...
...
@@ -79,6 +79,29 @@ export function findFirst<T>(array: T[], p: (x: T) => boolean): number {
return
low
;
}
/**
* Returns the top N elements from the array.
*
* Faster than sorting the entire array when the array is a lot larger than N.
*
* @param array The unsorted array.
* @param compare A sort function for the elements.
* @param n The number of elements to return.
* @return The first n elemnts from array when sorted with compare.
*/
export
function
top
<
T
>
(
array
:
T
[],
compare
:
(
a
:
T
,
b
:
T
)
=>
number
,
n
:
number
)
{
const
result
=
array
.
slice
(
0
,
n
).
sort
(
compare
);
for
(
let
i
=
n
,
m
=
array
.
length
;
i
<
m
;
i
++
)
{
const
element
=
array
[
i
];
if
(
compare
(
element
,
result
[
n
-
1
])
<
0
)
{
result
.
pop
();
const
j
=
findFirst
(
result
,
e
=>
compare
(
element
,
e
)
<
0
);
result
.
splice
(
j
,
0
,
element
);
}
}
return
result
;
}
export
function
merge
<
T
>
(
arrays
:
T
[][],
hashFn
?:
(
element
:
T
)
=>
string
):
T
[]
{
const
result
=
new
Array
<
T
>
();
if
(
!
hashFn
)
{
...
...
src/vs/base/common/comparers.ts
浏览文件 @
4c83c567
...
...
@@ -57,8 +57,8 @@ export function compareByPrefix(one: string, other: string, lookFor: string): nu
let
elementBName
=
other
.
toLowerCase
();
// Sort prefix matches over non prefix matches
let
elementAPrefixMatch
=
elementAName
.
indexOf
(
lookFor
)
===
0
;
let
elementBPrefixMatch
=
elementBName
.
indexOf
(
lookFor
)
===
0
;
let
elementAPrefixMatch
=
strings
.
startsWith
(
elementAName
,
lookFor
)
;
let
elementBPrefixMatch
=
strings
.
startsWith
(
elementBName
,
lookFor
)
;
if
(
elementAPrefixMatch
!==
elementBPrefixMatch
)
{
return
elementAPrefixMatch
?
-
1
:
1
;
}
...
...
src/vs/base/test/common/arrays.test.ts
浏览文件 @
4c83c567
...
...
@@ -60,5 +60,17 @@ suite('Arrays', () => {
assert
.
deepEqual
(
arrays
.
distinct
([
'
32
'
,
'
constructor
'
,
'
proto
'
,
'
proto
'
,
'
constructor
'
],
compare
),
[
'
32
'
,
'
constructor
'
,
'
proto
'
]);
assert
.
deepEqual
(
arrays
.
distinct
([
'
32
'
,
'
4
'
,
'
5
'
,
'
32
'
,
'
4
'
,
'
5
'
,
'
32
'
,
'
4
'
,
'
5
'
,
'
5
'
],
compare
),
[
'
32
'
,
'
4
'
,
'
5
'
]);
});
test
(
'
top
'
,
function
()
{
const
cmp
=
(
a
,
b
)
=>
a
-
b
;
assert
.
deepEqual
(
arrays
.
top
([],
cmp
,
1
),
[]);
assert
.
deepEqual
(
arrays
.
top
([
1
],
cmp
,
0
),
[]);
assert
.
deepEqual
(
arrays
.
top
([
1
,
2
],
cmp
,
1
),
[
1
]);
assert
.
deepEqual
(
arrays
.
top
([
2
,
1
],
cmp
,
1
),
[
1
]);
assert
.
deepEqual
(
arrays
.
top
([
1
,
3
,
2
],
cmp
,
2
),
[
1
,
2
]);
assert
.
deepEqual
(
arrays
.
top
([
3
,
2
,
1
],
cmp
,
3
),
[
1
,
2
,
3
]);
assert
.
deepEqual
(
arrays
.
top
([
4
,
6
,
2
,
7
,
8
,
3
,
5
,
1
],
cmp
,
3
),
[
1
,
2
,
3
]);
});
});
src/vs/workbench/parts/search/browser/openAnythingHandler.ts
浏览文件 @
4c83c567
...
...
@@ -5,6 +5,7 @@
'
use strict
'
;
import
*
as
arrays
from
'
vs/base/common/arrays
'
;
import
{
TPromise
}
from
'
vs/base/common/winjs.base
'
;
import
nls
=
require
(
'
vs/nls
'
);
import
{
ThrottledDelayer
}
from
'
vs/base/common/async
'
;
...
...
@@ -182,27 +183,19 @@ export class OpenAnythingHandler extends QuickOpenHandler {
// Combine symbol results and file results
let
result
=
[...
results
[
0
].
entries
,
...
results
[
1
].
entries
];
// Sort
const
normalizedSearchValue
=
strings
.
stripWildcards
(
searchValue
).
toLowerCase
();
result
.
sort
((
elementA
,
elementB
)
=>
QuickOpenEntry
.
compareByScore
(
elementA
,
elementB
,
searchValue
,
normalizedSearchValue
,
this
.
scorerCache
));
const
sortedResultTime
=
Date
.
now
();
// Apply Range
result
.
forEach
((
element
)
=>
{
if
(
element
instanceof
FileEntry
)
{
(
<
FileEntry
>
element
).
setRange
(
searchWithRange
?
searchWithRange
.
range
:
null
);
}
});
// Cache for fast lookup
this
.
resultsToSearchCache
[
searchValue
]
=
result
;
// Cap the number of results to make the view snappy
const
viewResults
=
result
.
length
>
OpenAnythingHandler
.
MAX_DISPLAYED_RESULTS
?
result
.
slice
(
0
,
OpenAnythingHandler
.
MAX_DISPLAYED_RESULTS
)
:
result
;
// Sort
const
normalizedSearchValue
=
strings
.
stripWildcards
(
searchValue
).
toLowerCase
();
const
compare
=
(
elementA
,
elementB
)
=>
QuickOpenEntry
.
compareByScore
(
elementA
,
elementB
,
searchValue
,
normalizedSearchValue
,
this
.
scorerCache
);
const
viewResults
=
arrays
.
top
(
result
,
compare
,
OpenAnythingHandler
.
MAX_DISPLAYED_RESULTS
);
const
sortedResultTime
=
Date
.
now
();
// Apply highlights to file entries
// Apply
range and
highlights to file entries
viewResults
.
forEach
(
entry
=>
{
if
(
entry
instanceof
FileEntry
)
{
entry
.
setRange
(
searchWithRange
?
searchWithRange
.
range
:
null
);
const
{
labelHighlights
,
descriptionHighlights
}
=
QuickOpenEntry
.
highlight
(
entry
,
searchValue
,
true
/* fuzzy highlight */
);
entry
.
setHighlights
(
labelHighlights
,
descriptionHighlights
);
}
...
...
@@ -324,21 +317,15 @@ export class OpenAnythingHandler extends QuickOpenHandler {
const
unsortedResultTime
=
Date
.
now
();
// Sort
results
.
sort
((
elementA
,
elementB
)
=>
QuickOpenEntry
.
compareByScore
(
elementA
,
elementB
,
searchValue
,
normalizedSearchValueLowercase
,
this
.
scorerCache
));
const
compare
=
(
elementA
,
elementB
)
=>
QuickOpenEntry
.
compareByScore
(
elementA
,
elementB
,
searchValue
,
normalizedSearchValueLowercase
,
this
.
scorerCache
);
const
viewResults
=
arrays
.
top
(
results
,
compare
,
OpenAnythingHandler
.
MAX_DISPLAYED_RESULTS
);
const
sortedResultTime
=
Date
.
now
();
// Apply Range
results
.
forEach
((
element
)
=>
{
if
(
element
instanceof
FileEntry
)
{
(
<
FileEntry
>
element
).
setRange
(
range
);
}
});
// Cap the number of results to make the view snappy
const
viewResults
=
results
.
length
>
OpenAnythingHandler
.
MAX_DISPLAYED_RESULTS
?
results
.
slice
(
0
,
OpenAnythingHandler
.
MAX_DISPLAYED_RESULTS
)
:
results
;
// Apply highlights
// Apply range and highlights
viewResults
.
forEach
(
entry
=>
{
if
(
entry
instanceof
FileEntry
)
{
entry
.
setRange
(
range
);
}
const
{
labelHighlights
,
descriptionHighlights
}
=
QuickOpenEntry
.
highlight
(
entry
,
searchValue
,
true
/* fuzzy highlight */
);
entry
.
setHighlights
(
labelHighlights
,
descriptionHighlights
);
});
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录