Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
acce4097
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,发现更多精彩内容 >>
提交
acce4097
编写于
9月 23, 2016
作者:
C
CyrusNajmabadi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Use pooled arrays.
上级
815e7539
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
32 addition
and
66 deletion
+32
-66
src/Workspaces/Core/Portable/FindSymbols/FindReferences/Finders/AbstractReferenceFinder.cs
...Symbols/FindReferences/Finders/AbstractReferenceFinder.cs
+12
-27
src/Workspaces/Core/Portable/FindSymbols/FindReferences/Finders/NamedTypeSymbolReferenceFinder.cs
.../FindReferences/Finders/NamedTypeSymbolReferenceFinder.cs
+9
-18
src/Workspaces/Core/Portable/FindSymbols/FindReferences/Finders/ParameterSymbolReferenceFinder.cs
.../FindReferences/Finders/ParameterSymbolReferenceFinder.cs
+9
-19
src/Workspaces/Core/Portable/FindSymbols/FindReferences/Finders/PropertySymbolReferenceFinder.cs
...s/FindReferences/Finders/PropertySymbolReferenceFinder.cs
+2
-2
未找到文件。
src/Workspaces/Core/Portable/FindSymbols/FindReferences/Finders/AbstractReferenceFinder.cs
浏览文件 @
acce4097
...
...
@@ -94,7 +94,7 @@ protected async Task<ImmutableArray<Document>> FindDocumentsAsync(Project projec
return
ImmutableArray
<
Document
>.
Empty
;
}
ImmutableArray
<
Document
>.
Builder
documents
=
null
;
var
documents
=
ArrayBuilder
<
Document
>.
GetInstance
()
;
foreach
(
var
document
in
project
.
Documents
)
{
if
(
scope
!=
null
&&
!
scope
.
Contains
(
document
))
...
...
@@ -104,19 +104,11 @@ protected async Task<ImmutableArray<Document>> FindDocumentsAsync(Project projec
if
(
await
predicateAsync
(
document
,
cancellationToken
).
ConfigureAwait
(
false
))
{
documents
=
documents
??
ImmutableArray
.
CreateBuilder
<
Document
>();
documents
.
Add
(
document
);
}
}
if
(
documents
==
null
)
{
return
ImmutableArray
<
Document
>.
Empty
;
}
else
{
return
documents
.
ToImmutable
();
}
return
documents
.
ToImmutableAndFree
();
}
/// <summary>
...
...
@@ -285,7 +277,7 @@ protected static bool IdentifiersMatch(ISyntaxFactsService syntaxFacts, string n
var
syntaxTree
=
await
document
.
GetSyntaxTreeAsync
(
cancellationToken
).
ConfigureAwait
(
false
);
var
semanticModel
=
await
document
.
GetSemanticModelAsync
(
cancellationToken
).
ConfigureAwait
(
false
);
var
locations
=
ImmutableArray
.
CreateBuilder
<
ReferenceLocation
>
();
var
locations
=
ArrayBuilder
<
ReferenceLocation
>.
GetInstance
();
foreach
(
var
token
in
tokens
)
{
cancellationToken
.
ThrowIfCancellationRequested
();
...
...
@@ -304,7 +296,7 @@ protected static bool IdentifiersMatch(ISyntaxFactsService syntaxFacts, string n
}
}
return
locations
.
ToImmutable
();
return
locations
.
ToImmutable
AndFree
();
}
protected
static
Task
<
ImmutableArray
<
ReferenceLocation
>>
FindReferencesInDocumentAsync
(
...
...
@@ -402,24 +394,17 @@ protected static bool IdentifiersMatch(ISyntaxFactsService syntaxFacts, string n
ImmutableArray
<
ReferenceLocation
>
nonAliasReferences
,
CancellationToken
cancellationToken
)
{
ImmutableArray
<
IAliasSymbol
>.
Builder
aliasSymbols
=
null
;
var
aliasSymbols
=
ArrayBuilder
<
IAliasSymbol
>.
GetInstance
()
;
foreach
(
var
r
in
nonAliasReferences
)
{
var
symbol
=
await
GetAliasSymbolAsync
(
document
,
r
,
cancellationToken
).
ConfigureAwait
(
false
);
if
(
symbol
!=
null
)
{
if
(
aliasSymbols
==
null
)
{
aliasSymbols
=
ImmutableArray
.
CreateBuilder
<
IAliasSymbol
>();
}
aliasSymbols
.
Add
(
symbol
);
}
}
return
aliasSymbols
!=
null
?
aliasSymbols
.
Distinct
().
ToImmutableArray
()
:
ImmutableArray
<
IAliasSymbol
>.
Empty
;
return
aliasSymbols
.
ToImmutableAndFree
();
}
private
static
async
Task
<
ImmutableArray
<
ReferenceLocation
>>
FindReferencesThroughAliasSymbolsAsync
(
...
...
@@ -430,7 +415,7 @@ protected static bool IdentifiersMatch(ISyntaxFactsService syntaxFacts, string n
CancellationToken
cancellationToken
)
{
var
syntaxFactsService
=
document
.
GetLanguageService
<
ISyntaxFactsService
>();
var
allAliasReferences
=
ImmutableArray
.
CreateBuilder
<
ReferenceLocation
>
();
var
allAliasReferences
=
ArrayBuilder
<
ReferenceLocation
>.
GetInstance
();
foreach
(
var
aliasSymbol
in
aliasSymbols
)
{
var
aliasReferences
=
await
FindReferencesInDocumentUsingIdentifierAsync
(
symbol
,
aliasSymbol
.
Name
,
document
,
cancellationToken
,
findParentNode
).
ConfigureAwait
(
false
);
...
...
@@ -446,7 +431,7 @@ protected static bool IdentifiersMatch(ISyntaxFactsService syntaxFacts, string n
}
}
return
allAliasReferences
.
ToImmutable
();
return
allAliasReferences
.
ToImmutable
AndFree
();
}
private
static
async
Task
<
ImmutableArray
<
ReferenceLocation
>>
FindReferencesThroughAliasSymbolsAsync
(
...
...
@@ -457,7 +442,7 @@ protected static bool IdentifiersMatch(ISyntaxFactsService syntaxFacts, string n
CancellationToken
cancellationToken
)
{
var
syntaxFactsService
=
document
.
GetLanguageService
<
ISyntaxFactsService
>();
var
allAliasReferences
=
ImmutableArray
.
CreateBuilder
<
ReferenceLocation
>
();
var
allAliasReferences
=
ArrayBuilder
<
ReferenceLocation
>.
GetInstance
();
foreach
(
var
aliasSymbol
in
aliasSymbols
)
{
var
aliasReferences
=
await
FindReferencesInDocumentUsingIdentifierAsync
(
aliasSymbol
.
Name
,
document
,
symbolsMatch
,
cancellationToken
).
ConfigureAwait
(
false
);
...
...
@@ -473,7 +458,7 @@ protected static bool IdentifiersMatch(ISyntaxFactsService syntaxFacts, string n
}
}
return
allAliasReferences
.
ToImmutable
();
return
allAliasReferences
.
ToImmutable
AndFree
();
}
protected
Task
<
ImmutableArray
<
Document
>>
FindDocumentsWithForEachStatementsAsync
(
Project
project
,
IImmutableSet
<
Document
>
documents
,
CancellationToken
cancellationToken
)
...
...
@@ -497,7 +482,7 @@ protected Task<ImmutableArray<Document>> FindDocumentsWithForEachStatementsAsync
var
syntaxRoot
=
await
document
.
GetSyntaxRootAsync
(
cancellationToken
).
ConfigureAwait
(
false
);
var
semanticModel
=
await
document
.
GetSemanticModelAsync
(
cancellationToken
).
ConfigureAwait
(
false
);
var
locations
=
ImmutableArray
.
CreateBuilder
<
ReferenceLocation
>
();
var
locations
=
ArrayBuilder
<
ReferenceLocation
>.
GetInstance
();
var
originalUnreducedSymbolDefinition
=
symbol
.
GetOriginalUnreducedDefinition
();
...
...
@@ -517,7 +502,7 @@ protected Task<ImmutableArray<Document>> FindDocumentsWithForEachStatementsAsync
}
}
return
locations
.
ToImmutable
();
return
locations
.
ToImmutable
AndFree
();
}
else
{
...
...
src/Workspaces/Core/Portable/FindSymbols/FindReferences/Finders/NamedTypeSymbolReferenceFinder.cs
浏览文件 @
acce4097
...
...
@@ -25,41 +25,32 @@ protected override bool CanFind(INamedTypeSymbol symbol)
IImmutableSet
<
Project
>
projects
,
CancellationToken
cancellationToken
)
{
ImmutableArray
<
SymbolAndProjectId
>.
Builder
result
=
null
;
var
result
=
ArrayBuilder
<
SymbolAndProjectId
>.
GetInstance
()
;
var
symbol
=
symbolAndProjectId
.
Symbol
;
if
(
symbol
.
AssociatedSymbol
!=
null
)
{
result
=
Add
(
result
,
symbolAndProjectId
,
ImmutableArray
.
Create
(
symbol
.
AssociatedSymbol
));
Add
(
result
,
symbolAndProjectId
,
ImmutableArray
.
Create
(
symbol
.
AssociatedSymbol
));
}
// cascade to constructors
result
=
Add
(
result
,
symbolAndProjectId
,
symbol
.
Constructors
);
Add
(
result
,
symbolAndProjectId
,
symbol
.
Constructors
);
// cascade to destructor
result
=
Add
(
result
,
symbolAndProjectId
,
symbol
.
GetMembers
(
WellKnownMemberNames
.
DestructorName
));
Add
(
result
,
symbolAndProjectId
,
symbol
.
GetMembers
(
WellKnownMemberNames
.
DestructorName
));
return
Task
.
FromResult
<
ImmutableArray
<
SymbolAndProjectId
>>(
result
==
null
?
ImmutableArray
<
SymbolAndProjectId
>.
Empty
:
result
.
ToImmutable
());
return
Task
.
FromResult
(
result
.
ToImmutableAndFree
());
}
private
ImmutableArray
<
SymbolAndProjectId
>.
Builder
Add
<
TSymbol
>(
ImmutableArray
<
SymbolAndProjectId
>.
Builder
result
,
private
void
Add
<
TSymbol
>(
ArrayBuilder
<
SymbolAndProjectId
>
result
,
SymbolAndProjectId
symbolAndProjectId
,
ImmutableArray
<
TSymbol
>
enumerable
)
where
TSymbol
:
ISymbol
{
if
(
enumerable
!=
null
)
{
result
=
result
??
ImmutableArray
.
CreateBuilder
<
SymbolAndProjectId
>();
result
.
AddRange
(
enumerable
.
Select
(
s
=>
symbolAndProjectId
.
WithSymbol
((
ISymbol
)
s
)));
}
return
result
;
}
protected
override
async
Task
<
ImmutableArray
<
Document
>>
DetermineDocumentsToSearchAsync
(
INamedTypeSymbol
symbol
,
Project
project
,
...
...
src/Workspaces/Core/Portable/FindSymbols/FindReferences/Finders/ParameterSymbolReferenceFinder.cs
浏览文件 @
acce4097
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using
System.Collections.Generic
;
using
System.Collections.Immutable
;
using
System.Linq
;
using
System.Threading
;
...
...
@@ -8,7 +7,6 @@
using
Microsoft.CodeAnalysis.LanguageServices
;
using
Microsoft.CodeAnalysis.Shared.Extensions
;
using
Microsoft.CodeAnalysis.Shared.Utilities
;
using
Roslyn.Utilities
;
namespace
Microsoft.CodeAnalysis.FindSymbols.Finders
{
...
...
@@ -69,7 +67,7 @@ protected override bool CanFind(IParameterSymbol symbol)
SymbolAndProjectId
<
IParameterSymbol
>
parameterAndProjectId
,
CancellationToken
cancellationToken
)
{
ImmutableArray
<
SymbolAndProjectId
>.
Builder
results
=
null
;
var
results
=
ArrayBuilder
<
SymbolAndProjectId
>.
GetInstance
()
;
var
parameter
=
parameterAndProjectId
.
Symbol
;
if
(
parameter
.
ContainingSymbol
.
IsAnonymousFunction
())
...
...
@@ -94,7 +92,6 @@ protected override bool CanFind(IParameterSymbol symbol)
var
container
=
GetContainer
(
semanticModel
,
parameterNode
,
syntaxFactsService
);
if
(
container
!=
null
)
{
results
=
ImmutableArray
.
CreateBuilder
<
SymbolAndProjectId
>();
results
.
AddRange
(
CascadeBetweenAnonymousFunctionParameters
(
document
,
semanticModel
,
container
,
parameterAndProjectId
,
convertedType
,
cancellationToken
));
}
...
...
@@ -110,20 +107,13 @@ protected override bool CanFind(IParameterSymbol symbol)
int
ordinal
=
parameter
.
Ordinal
;
if
(
invokeMethod
!=
null
&&
ordinal
<
invokeMethod
.
Parameters
.
Length
)
{
if
(
results
==
null
)
{
results
=
ImmutableArray
.
CreateBuilder
<
SymbolAndProjectId
>();
}
results
.
Add
(
parameterAndProjectId
.
WithSymbol
(
invokeMethod
.
Parameters
[
ordinal
]));
}
}
}
return
results
==
null
?
ImmutableArray
<
SymbolAndProjectId
>.
Empty
:
results
.
ToImmutable
();
return
results
.
ToImmutableAndFree
();
}
private
ImmutableArray
<
SymbolAndProjectId
>
CascadeBetweenAnonymousFunctionParameters
(
...
...
@@ -134,7 +124,7 @@ protected override bool CanFind(IParameterSymbol symbol)
ITypeSymbol
convertedType1
,
CancellationToken
cancellationToken
)
{
var
result
=
ImmutableArray
.
CreateBuilder
<
SymbolAndProjectId
>
();
var
result
=
ArrayBuilder
<
SymbolAndProjectId
>.
GetInstance
();
var
parameter
=
parameterAndProjectId
.
Symbol
;
var
syntaxFacts
=
document
.
GetLanguageService
<
ISyntaxFactsService
>();
...
...
@@ -159,7 +149,7 @@ protected override bool CanFind(IParameterSymbol symbol)
}
}
return
result
.
ToImmutable
();
return
result
.
ToImmutable
AndFree
();
}
private
bool
ParameterNamesMatch
(
ISyntaxFactsService
syntaxFacts
,
IMethodSymbol
methodSymbol1
,
IMethodSymbol
methodSymbol2
)
...
...
@@ -195,7 +185,7 @@ private SyntaxNode GetContainer(SemanticModel semanticModel, SyntaxNode paramete
SymbolAndProjectId
<
IParameterSymbol
>
parameterAndProjectId
,
CancellationToken
cancellationToken
)
{
var
results
=
ImmutableArray
.
CreateBuilder
<
SymbolAndProjectId
>
();
var
results
=
ArrayBuilder
<
SymbolAndProjectId
>.
GetInstance
();
var
parameter
=
parameterAndProjectId
.
Symbol
;
var
ordinal
=
parameter
.
Ordinal
;
...
...
@@ -278,13 +268,13 @@ private SyntaxNode GetContainer(SemanticModel semanticModel, SyntaxNode paramete
}
}
return
results
.
ToImmutable
();
return
results
.
ToImmutable
AndFree
();
}
private
ImmutableArray
<
SymbolAndProjectId
>
CascadeBetweenPartialMethodParameters
(
SymbolAndProjectId
<
IParameterSymbol
>
parameterAndProjectId
)
{
var
result
=
ImmutableArray
.
CreateBuilder
<
SymbolAndProjectId
>
();
var
result
=
ArrayBuilder
<
SymbolAndProjectId
>.
GetInstance
();
var
parameter
=
parameterAndProjectId
.
Symbol
;
if
(
parameter
.
ContainingSymbol
is
IMethodSymbol
)
...
...
@@ -304,7 +294,7 @@ private SyntaxNode GetContainer(SemanticModel semanticModel, SyntaxNode paramete
}
}
return
result
.
ToImmutable
();
return
result
.
ToImmutable
AndFree
();
}
}
}
\ No newline at end of file
src/Workspaces/Core/Portable/FindSymbols/FindReferences/Finders/PropertySymbolReferenceFinder.cs
浏览文件 @
acce4097
...
...
@@ -135,7 +135,7 @@ private static bool IsForEachProperty(IPropertySymbol symbol)
var
elementAccessExpressionsAndIndexerMemberCref
=
elementAccessExpressions
.
Concat
(
indexerMemberCref
);
var
locations
=
ImmutableArray
.
CreateBuilder
<
ReferenceLocation
>
();
var
locations
=
ArrayBuilder
<
ReferenceLocation
>.
GetInstance
();
foreach
(
var
node
in
elementAccessExpressionsAndIndexerMemberCref
)
{
...
...
@@ -172,7 +172,7 @@ private static bool IsForEachProperty(IPropertySymbol symbol)
}
}
return
locations
.
ToImmutable
();
return
locations
.
ToImmutable
AndFree
();
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录