Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
c78dcf79
R
roslyn
项目概览
lwm1986
/
roslyn
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
roslyn
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
c78dcf79
编写于
9月 27, 2016
作者:
C
CyrusNajmabadi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Reduce the number of intermediary IEnumerables we create while building indices.
上级
83346efe
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
84 addition
and
60 deletion
+84
-60
src/Features/Core/Portable/CodeFixes/AddImport/AbstractAddImportCodeFixProvider.SearchScope.cs
...AddImport/AbstractAddImportCodeFixProvider.SearchScope.cs
+8
-6
src/Workspaces/Core/Portable/FindSymbols/SymbolFinder_Declarations.cs
...es/Core/Portable/FindSymbols/SymbolFinder_Declarations.cs
+24
-14
src/Workspaces/Core/Portable/FindSymbols/SymbolTree/SymbolTreeInfo.cs
...es/Core/Portable/FindSymbols/SymbolTree/SymbolTreeInfo.cs
+52
-40
未找到文件。
src/Features/Core/Portable/CodeFixes/AddImport/AbstractAddImportCodeFixProvider.SearchScope.cs
浏览文件 @
c78dcf79
...
...
@@ -2,6 +2,7 @@
using
System.Collections.Concurrent
;
using
System.Collections.Generic
;
using
System.Collections.Immutable
;
using
System.Diagnostics
;
using
System.Linq
;
using
System.Threading
;
...
...
@@ -34,7 +35,7 @@ protected SearchScope(AbstractAddImportCodeFixProvider<TSimpleNameSyntax> provid
CancellationToken
=
cancellationToken
;
}
protected
abstract
Task
<
I
Enumerable
<
ISymbol
>>
FindDeclarationsAsync
(
string
name
,
SymbolFilter
filter
,
SearchQuery
query
);
protected
abstract
Task
<
I
mmutableArray
<
ISymbol
>>
FindDeclarationsAsync
(
string
name
,
SymbolFilter
filter
,
SearchQuery
query
);
public
abstract
SymbolReference
CreateReference
<
T
>(
SymbolResult
<
T
>
symbol
)
where
T
:
INamespaceOrTypeSymbol
;
public
async
Task
<
IEnumerable
<
SymbolResult
<
ISymbol
>>>
FindDeclarationsAsync
(
...
...
@@ -109,7 +110,7 @@ private class AllSymbolsProjectSearchScope : ProjectSearchScope
{
}
protected
override
Task
<
I
Enumerable
<
ISymbol
>>
FindDeclarationsAsync
(
protected
override
Task
<
I
mmutableArray
<
ISymbol
>>
FindDeclarationsAsync
(
string
name
,
SymbolFilter
filter
,
SearchQuery
searchQuery
)
{
return
SymbolFinder
.
FindDeclarationsAsync
(
_project
,
searchQuery
,
filter
,
CancellationToken
);
...
...
@@ -133,14 +134,15 @@ private class SourceSymbolsProjectSearchScope : ProjectSearchScope
_projectToAssembly
=
projectToAssembly
;
}
protected
override
async
Task
<
IEnumerable
<
ISymbol
>>
FindDeclarationsAsync
(
string
name
,
SymbolFilter
filter
,
SearchQuery
searchQuery
)
protected
override
async
Task
<
ImmutableArray
<
ISymbol
>>
FindDeclarationsAsync
(
string
name
,
SymbolFilter
filter
,
SearchQuery
searchQuery
)
{
var
service
=
_project
.
Solution
.
Workspace
.
Services
.
GetService
<
ISymbolTreeInfoCacheService
>();
var
info
=
await
service
.
TryGetSourceSymbolTreeInfoAsync
(
_project
,
CancellationToken
).
ConfigureAwait
(
false
);
if
(
info
==
null
)
{
// Looks like there was nothing in the cache. Return no results for now.
return
SpecializedCollections
.
EmptyEnumerable
<
ISymbol
>()
;
return
ImmutableArray
<
ISymbol
>.
Empty
;
}
// Don't create the assembly until it is actually needed by the SymbolTreeInfo.FindAsync
...
...
@@ -190,14 +192,14 @@ public override SymbolReference CreateReference<T>(SymbolResult<T> searchResult)
_metadataReference
);
}
protected
override
async
Task
<
I
Enumerable
<
ISymbol
>>
FindDeclarationsAsync
(
protected
override
async
Task
<
I
mmutableArray
<
ISymbol
>>
FindDeclarationsAsync
(
string
name
,
SymbolFilter
filter
,
SearchQuery
searchQuery
)
{
var
service
=
_solution
.
Workspace
.
Services
.
GetService
<
ISymbolTreeInfoCacheService
>();
var
info
=
await
service
.
TryGetMetadataSymbolTreeInfoAsync
(
_solution
,
_metadataReference
,
CancellationToken
).
ConfigureAwait
(
false
);
if
(
info
==
null
)
{
return
SpecializedCollections
.
EmptyEnumerable
<
ISymbol
>()
;
return
ImmutableArray
<
ISymbol
>.
Empty
;
}
return
await
info
.
FindAsync
(
searchQuery
,
_assembly
,
filter
,
CancellationToken
).
ConfigureAwait
(
false
);
...
...
src/Workspaces/Core/Portable/FindSymbols/SymbolFinder_Declarations.cs
浏览文件 @
c78dcf79
...
...
@@ -2,6 +2,7 @@
using
System
;
using
System.Collections.Generic
;
using
System.Collections.Immutable
;
using
System.Diagnostics
;
using
System.Linq
;
using
System.Threading
;
...
...
@@ -117,7 +118,7 @@ public static partial class SymbolFinder
/// <summary>
/// Find the declared symbols from either source, referenced projects or metadata assemblies with the specified name.
/// </summary>
public
static
Task
<
IEnumerable
<
ISymbol
>>
FindDeclarationsAsync
(
public
static
async
Task
<
IEnumerable
<
ISymbol
>>
FindDeclarationsAsync
(
Project
project
,
string
name
,
bool
ignoreCase
,
CancellationToken
cancellationToken
=
default
(
CancellationToken
))
{
if
(
name
==
null
)
...
...
@@ -127,16 +128,17 @@ public static partial class SymbolFinder
if
(
string
.
IsNullOrWhiteSpace
(
name
))
{
return
SpecializedTasks
.
EmptyEnumerable
<
ISymbol
>()
;
return
ImmutableArray
<
ISymbol
>.
Empty
;
}
return
FindDeclarationsAsync
(
project
,
SearchQuery
.
Create
(
name
,
ignoreCase
),
SymbolFilter
.
All
,
cancellationToken
:
cancellationToken
);
return
await
FindDeclarationsAsync
(
project
,
SearchQuery
.
Create
(
name
,
ignoreCase
),
SymbolFilter
.
All
,
cancellationToken
:
cancellationToken
).
ConfigureAwait
(
false
);
}
/// <summary>
/// Find the declared symbols from either source, referenced projects or metadata assemblies with the specified name.
/// </summary>
public
static
Task
<
IEnumerable
<
ISymbol
>>
FindDeclarationsAsync
(
public
static
async
Task
<
IEnumerable
<
ISymbol
>>
FindDeclarationsAsync
(
Project
project
,
string
name
,
bool
ignoreCase
,
SymbolFilter
filter
,
CancellationToken
cancellationToken
=
default
(
CancellationToken
))
{
if
(
name
==
null
)
...
...
@@ -146,13 +148,14 @@ public static partial class SymbolFinder
if
(
string
.
IsNullOrWhiteSpace
(
name
))
{
return
SpecializedTasks
.
EmptyEnumerable
<
ISymbol
>()
;
return
ImmutableArray
<
ISymbol
>.
Empty
;
}
return
FindDeclarationsAsync
(
project
,
SearchQuery
.
Create
(
name
,
ignoreCase
),
filter
,
cancellationToken
:
cancellationToken
);
return
await
FindDeclarationsAsync
(
project
,
SearchQuery
.
Create
(
name
,
ignoreCase
),
filter
,
cancellationToken
:
cancellationToken
).
ConfigureAwait
(
false
);
}
internal
static
Task
<
I
Enumerable
<
ISymbol
>>
FindDeclarationsAsync
(
internal
static
Task
<
I
mmutableArray
<
ISymbol
>>
FindDeclarationsAsync
(
Project
project
,
SearchQuery
query
,
SymbolFilter
filter
,
CancellationToken
cancellationToken
)
{
// All entrypoints to this function are Find functions that are only searching
...
...
@@ -166,7 +169,7 @@ public static partial class SymbolFinder
if
(
query
.
Name
!=
null
&&
string
.
IsNullOrWhiteSpace
(
query
.
Name
))
{
return
SpecializedTasks
.
Empty
Enumerable
<
ISymbol
>();
return
SpecializedTasks
.
Empty
ImmutableArray
<
ISymbol
>();
}
using
(
Logger
.
LogBlock
(
FunctionId
.
SymbolFinder_FindDeclarationsAsync
,
cancellationToken
))
...
...
@@ -175,7 +178,7 @@ public static partial class SymbolFinder
}
}
private
static
async
Task
<
I
Enumerable
<
ISymbol
>>
FindDeclarationsAsyncImpl
(
private
static
async
Task
<
I
mmutableArray
<
ISymbol
>>
FindDeclarationsAsyncImpl
(
Project
project
,
SearchQuery
query
,
SymbolFilter
criteria
,
CancellationToken
cancellationToken
)
{
// All entrypoints to this function are Find functions that are only searching
...
...
@@ -216,20 +219,23 @@ private static string GetMetadataReferenceFilePath(MetadataReference metadataRef
/// <summary>
/// Makes certain all namespace symbols returned by API are from the compilation.
/// </summary>
private
static
I
Enumerable
<
ISymbol
>
TranslateNamespaces
(
List
<
ISymbol
>
symbols
,
Compilation
compilation
)
private
static
I
mmutableArray
<
ISymbol
>
TranslateNamespaces
(
List
<
ISymbol
>
symbols
,
Compilation
compilation
)
{
var
result
=
ArrayBuilder
<
ISymbol
>.
GetInstance
();
foreach
(
var
symbol
in
symbols
)
{
var
ns
=
symbol
as
INamespaceSymbol
;
if
(
ns
!=
null
)
{
yield
return
compilation
.
GetCompilationNamespace
(
ns
);
result
.
Add
(
compilation
.
GetCompilationNamespace
(
ns
)
);
}
else
{
yield
return
symbol
;
result
.
Add
(
symbol
)
;
}
}
return
result
.
ToImmutableAndFree
();
}
private
static
async
Task
AddDeclarationsAsync
(
...
...
@@ -479,8 +485,10 @@ internal static async Task<IEnumerable<ISymbol>> FindSourceDeclarationsAsync(Pro
}
}
internal
static
IEnumerable
<
ISymbol
>
FilterByCriteria
(
IEnumerable
<
ISymbol
>
symbols
,
SymbolFilter
criteria
)
internal
static
ImmutableArray
<
ISymbol
>
FilterByCriteria
(
IEnumerable
<
ISymbol
>
symbols
,
SymbolFilter
criteria
)
{
var
result
=
ArrayBuilder
<
ISymbol
>.
GetInstance
();
foreach
(
var
symbol
in
symbols
)
{
if
(
symbol
.
IsImplicitlyDeclared
||
symbol
.
IsAccessor
())
...
...
@@ -490,9 +498,11 @@ internal static IEnumerable<ISymbol> FilterByCriteria(IEnumerable<ISymbol> symbo
if
(
MeetCriteria
(
symbol
,
criteria
))
{
yield
return
symbol
;
result
.
Add
(
symbol
)
;
}
}
return
result
.
ToImmutableAndFree
();
}
private
static
bool
MeetCriteria
(
ISymbol
symbol
,
SymbolFilter
filter
)
...
...
src/Workspaces/Core/Portable/FindSymbols/SymbolTree/SymbolTreeInfo.cs
浏览文件 @
c78dcf79
...
...
@@ -114,7 +114,7 @@ internal partial class SymbolTreeInfo
_spellCheckerTask
=
spellCheckerTask
;
}
public
Task
<
I
Enumerable
<
ISymbol
>>
FindAsync
(
public
Task
<
I
mmutableArray
<
ISymbol
>>
FindAsync
(
SearchQuery
query
,
IAssemblySymbol
assembly
,
SymbolFilter
filter
,
CancellationToken
cancellationToken
)
{
// All entrypoints to this function are Find functions that are only searching
...
...
@@ -124,7 +124,7 @@ internal partial class SymbolTreeInfo
return
this
.
FindAsync
(
query
,
new
AsyncLazy
<
IAssemblySymbol
>(
assembly
),
filter
,
cancellationToken
);
}
public
async
Task
<
I
Enumerable
<
ISymbol
>>
FindAsync
(
public
async
Task
<
I
mmutableArray
<
ISymbol
>>
FindAsync
(
SearchQuery
query
,
AsyncLazy
<
IAssemblySymbol
>
lazyAssembly
,
SymbolFilter
filter
,
CancellationToken
cancellationToken
)
{
// All entrypoints to this function are Find functions that are only searching
...
...
@@ -136,7 +136,7 @@ internal partial class SymbolTreeInfo
filter
);
}
private
Task
<
I
Enumerable
<
ISymbol
>>
FindAsyncWorker
(
private
Task
<
I
mmutableArray
<
ISymbol
>>
FindAsyncWorker
(
SearchQuery
query
,
AsyncLazy
<
IAssemblySymbol
>
lazyAssembly
,
CancellationToken
cancellationToken
)
{
// All entrypoints to this function are Find functions that are only searching
...
...
@@ -161,18 +161,18 @@ internal partial class SymbolTreeInfo
/// <summary>
/// Finds symbols in this assembly that match the provided name in a fuzzy manner.
/// </summary>
private
async
Task
<
I
Enumerable
<
ISymbol
>>
FuzzyFindAsync
(
private
async
Task
<
I
mmutableArray
<
ISymbol
>>
FuzzyFindAsync
(
AsyncLazy
<
IAssemblySymbol
>
lazyAssembly
,
string
name
,
CancellationToken
cancellationToken
)
{
if
(
_spellCheckerTask
.
Status
!=
TaskStatus
.
RanToCompletion
)
{
// Spell checker isn't ready. Just return immediately.
return
SpecializedCollections
.
EmptyEnumerable
<
ISymbol
>()
;
return
ImmutableArray
<
ISymbol
>.
Empty
;
}
var
spellChecker
=
_spellCheckerTask
.
Result
;
var
similarNames
=
spellChecker
.
FindSimilarWords
(
name
,
substringsAreSimilar
:
false
);
var
result
=
new
List
<
ISymbol
>
();
var
result
=
ArrayBuilder
<
ISymbol
>.
GetInstance
();
foreach
(
var
similarName
in
similarNames
)
{
...
...
@@ -180,20 +180,20 @@ internal partial class SymbolTreeInfo
result
.
AddRange
(
symbols
);
}
return
result
;
return
result
.
ToImmutableAndFree
()
;
}
/// <summary>
/// Get all symbols that have a name matching the specified name.
/// </summary>
private
async
Task
<
I
Enumerable
<
ISymbol
>>
FindAsync
(
private
async
Task
<
I
mmutableArray
<
ISymbol
>>
FindAsync
(
AsyncLazy
<
IAssemblySymbol
>
lazyAssembly
,
string
name
,
bool
ignoreCase
,
CancellationToken
cancellationToken
)
{
var
comparer
=
GetComparer
(
ignoreCase
);
var
result
=
new
List
<
ISymbol
>
();
var
result
s
=
ArrayBuilder
<
ISymbol
>.
GetInstance
();
IAssemblySymbol
assemblySymbol
=
null
;
foreach
(
var
node
in
FindNodeIndices
(
name
,
comparer
))
...
...
@@ -201,10 +201,10 @@ internal partial class SymbolTreeInfo
cancellationToken
.
ThrowIfCancellationRequested
();
assemblySymbol
=
assemblySymbol
??
await
lazyAssembly
.
GetValueAsync
(
cancellationToken
).
ConfigureAwait
(
false
);
result
.
AddRange
(
Bind
(
node
,
assemblySymbol
.
GlobalNamespace
,
cancellationToken
)
);
Bind
(
node
,
assemblySymbol
.
GlobalNamespace
,
results
,
cancellationToken
);
}
return
result
;
return
result
s
.
ToImmutableAndFree
();
;
}
private
static
StringSliceComparer
GetComparer
(
bool
ignoreCase
)
...
...
@@ -409,26 +409,8 @@ private int BinarySearch(string name)
#
region
Binding
// returns all the symbols in the container corresponding to the node
private
IEnumerable
<
ISymbol
>
Bind
(
int
index
,
INamespaceOrTypeSymbol
rootContainer
,
CancellationToken
cancellationToken
)
{
cancellationToken
.
ThrowIfCancellationRequested
();
using
(
var
symbols
=
SharedPools
.
Default
<
List
<
ISymbol
>>().
GetPooledObject
())
{
BindWorker
(
index
,
rootContainer
,
symbols
.
Object
,
cancellationToken
);
foreach
(
var
symbol
in
symbols
.
Object
)
{
cancellationToken
.
ThrowIfCancellationRequested
();
yield
return
symbol
;
}
}
}
// returns all the symbols in the container corresponding to the node
private
void
BindWorker
(
int
index
,
INamespaceOrTypeSymbol
rootContainer
,
List
<
ISymbol
>
results
,
CancellationToken
cancellationToken
)
private
void
Bind
(
int
index
,
INamespaceOrTypeSymbol
rootContainer
,
ArrayBuilder
<
ISymbol
>
results
,
CancellationToken
cancellationToken
)
{
cancellationToken
.
ThrowIfCancellationRequested
();
...
...
@@ -444,17 +426,26 @@ private int BinarySearch(string name)
}
else
{
using
(
var
containerSymbols
=
SharedPools
.
Default
<
List
<
ISymbol
>>().
GetPooledObject
())
var
containerSymbols
=
ArrayBuilder
<
ISymbol
>.
GetInstance
();
try
{
Bind
Worker
(
node
.
ParentIndex
,
rootContainer
,
containerSymbols
.
Object
,
cancellationToken
);
Bind
(
node
.
ParentIndex
,
rootContainer
,
containerSymbols
,
cancellationToken
);
foreach
(
var
containerSymbol
in
containerSymbols
.
Object
.
OfType
<
INamespaceOrTypeSymbol
>()
)
foreach
(
var
containerSymbol
in
containerSymbols
)
{
cancellationToken
.
ThrowIfCancellationRequested
();
results
.
AddRange
(
containerSymbol
.
GetMembers
(
GetName
(
node
)));
var
nsOrType
=
containerSymbol
as
INamespaceOrTypeSymbol
;
if
(
nsOrType
!=
null
)
{
results
.
AddRange
(
nsOrType
.
GetMembers
(
GetName
(
node
)));
}
}
}
finally
{
containerSymbols
.
Free
();
}
}
}
...
...
@@ -541,16 +532,37 @@ internal void AssertEquivalentTo(SymbolTreeInfo other)
return
result
;
}
public
I
Enumerable
<
INamedTypeSymbol
>
GetDerivedMetadataTypes
(
public
I
mmutableArray
<
INamedTypeSymbol
>
GetDerivedMetadataTypes
(
string
baseTypeName
,
Compilation
compilation
,
CancellationToken
cancellationToken
)
{
var
baseTypeNameIndex
=
BinarySearch
(
baseTypeName
);
var
derivedTypeIndices
=
_inheritanceMap
[
baseTypeNameIndex
];
return
from
derivedTypeIndex
in
derivedTypeIndices
from
symbol
in
Bind
(
derivedTypeIndex
,
compilation
.
GlobalNamespace
,
cancellationToken
)
let
namedType
=
symbol
as
INamedTypeSymbol
select
namedType
;
var
builder
=
ArrayBuilder
<
INamedTypeSymbol
>.
GetInstance
();
foreach
(
var
derivedTypeIndex
in
derivedTypeIndices
)
{
var
tempBuilder
=
ArrayBuilder
<
ISymbol
>.
GetInstance
();
try
{
Bind
(
derivedTypeIndex
,
compilation
.
GlobalNamespace
,
tempBuilder
,
cancellationToken
);
foreach
(
var
symbol
in
tempBuilder
)
{
var
namedType
=
symbol
as
INamedTypeSymbol
;
if
(
namedType
!=
null
)
{
builder
.
Add
(
namedType
);
}
}
}
finally
{
tempBuilder
.
Free
();
}
}
return
builder
.
ToImmutableAndFree
();
}
}
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录