Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
feb0866a
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,发现更多精彩内容 >>
提交
feb0866a
编写于
4月 22, 2018
作者:
C
Cyrus Najmabadi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add faster 'ContainsName' helpers as well.
上级
a6628b50
变更
5
显示空白变更内容
内联
并排
Showing
5 changed file
with
133 addition
and
22 deletion
+133
-22
src/Compilers/CSharp/Portable/Compilation/CSharpCompilation.cs
...ompilers/CSharp/Portable/Compilation/CSharpCompilation.cs
+23
-1
src/Compilers/CSharp/Portable/Declarations/DeclarationTable.cs
...ompilers/CSharp/Portable/Declarations/DeclarationTable.cs
+45
-11
src/Compilers/Core/Portable/Compilation/Compilation.cs
src/Compilers/Core/Portable/Compilation/Compilation.cs
+10
-1
src/Compilers/VisualBasic/Portable/Compilation/VisualBasicCompilation.vb
...isualBasic/Portable/Compilation/VisualBasicCompilation.vb
+12
-0
src/Compilers/VisualBasic/Portable/Declarations/DeclarationTable.vb
...ers/VisualBasic/Portable/Declarations/DeclarationTable.vb
+43
-9
未找到文件。
src/Compilers/CSharp/Portable/Compilation/CSharpCompilation.cs
浏览文件 @
feb0866a
...
...
@@ -3038,7 +3038,29 @@ public override IEnumerable<ISymbol> GetSymbolsWithName(Func<string, bool> predi
}
/// <summary>
/// Return source declaration symbols whose name matches the provided name
/// Return true if there is a source declaration symbol name that matches the provided name.
/// This will be faster than <see cref="ContainsSymbolsWithName(Func{string, bool}, SymbolFilter, CancellationToken)"/>
/// when predicate is just a simple string check.
/// </summary>
internal
override
bool
ContainsSymbolsWithName
(
string
name
,
SymbolFilter
filter
=
SymbolFilter
.
TypeAndMember
,
CancellationToken
cancellationToken
=
default
(
CancellationToken
))
{
if
(
name
==
null
)
{
throw
new
ArgumentNullException
(
nameof
(
name
));
}
if
(
filter
==
SymbolFilter
.
None
)
{
throw
new
ArgumentException
(
CSharpResources
.
NoNoneSearchCriteria
,
nameof
(
filter
));
}
return
DeclarationTable
.
ContainsName
(
this
.
MergedRootDeclaration
,
name
,
filter
,
cancellationToken
);
}
/// <summary>
/// Return source declaration symbols whose name matches the provided name. This will be
/// faster than <see cref="GetSymbolsWithName(Func{string, bool}, SymbolFilter, CancellationToken)"/>
/// when predicate is just a simple string check.
/// </summary>
internal
override
IEnumerable
<
ISymbol
>
GetSymbolsWithName
(
string
name
,
SymbolFilter
filter
=
SymbolFilter
.
TypeAndMember
,
CancellationToken
cancellationToken
=
default
(
CancellationToken
))
{
...
...
src/Compilers/CSharp/Portable/Declarations/DeclarationTable.cs
浏览文件 @
feb0866a
...
...
@@ -264,11 +264,48 @@ public IEnumerable<ReferenceDirective> ReferenceDirectives
}
}
public
static
bool
ContainsName
(
MergedNamespaceDeclaration
mergedRoot
,
string
name
,
SymbolFilter
filter
,
CancellationToken
cancellationToken
)
{
return
ContainsNameHelper
(
mergedRoot
,
n
=>
n
==
name
,
filter
,
t
=>
t
.
MemberNames
.
Contains
(
name
),
cancellationToken
);
}
public
static
bool
ContainsName
(
MergedNamespaceDeclaration
mergedRoot
,
Func
<
string
,
bool
>
predicate
,
SymbolFilter
filter
,
CancellationToken
cancellationToken
)
{
return
ContainsNameHelper
(
mergedRoot
,
predicate
,
filter
,
t
=>
{
foreach
(
var
name
in
t
.
MemberNames
)
{
if
(
predicate
(
name
))
{
return
true
;
}
}
return
false
;
},
cancellationToken
);
}
private
static
bool
ContainsNameHelper
(
MergedNamespaceDeclaration
mergedRoot
,
Func
<
string
,
bool
>
predicate
,
SymbolFilter
filter
,
Func
<
SingleTypeDeclaration
,
bool
>
typePredicate
,
CancellationToken
cancellationToken
)
{
var
includeNamespace
=
(
filter
&
SymbolFilter
.
Namespace
)
==
SymbolFilter
.
Namespace
;
var
includeType
=
(
filter
&
SymbolFilter
.
Type
)
==
SymbolFilter
.
Type
;
...
...
@@ -304,9 +341,9 @@ public IEnumerable<ReferenceDirective> ReferenceDirectives
if
(
includeMember
)
{
var
mergedType
=
(
MergedTypeDeclaration
)
current
;
foreach
(
var
name
in
mergedType
.
MemberName
s
)
foreach
(
var
typeDecl
in
mergedType
.
Declaration
s
)
{
if
(
predicate
(
name
))
if
(
typePredicate
(
typeDecl
))
{
return
true
;
}
...
...
@@ -314,17 +351,14 @@ public IEnumerable<ReferenceDirective> ReferenceDirectives
}
}
foreach
(
var
child
in
current
.
Children
.
OfType
<
MergedNamespaceOrTypeDeclaration
>()
)
foreach
(
var
child
in
current
.
Children
)
{
if
(
includeMember
||
include
Type
)
if
(
child
is
MergedNamespaceOrTypeDeclaration
childNamespaceOr
Type
)
{
stack
.
Push
(
child
);
continue
;
}
if
(
child
.
Kind
==
DeclarationKind
.
Namespace
)
if
(
includeMember
||
includeType
||
childNamespaceOrType
.
Kind
==
DeclarationKind
.
Namespace
)
{
stack
.
Push
(
child
);
stack
.
Push
(
childNamespaceOrType
);
}
}
}
}
...
...
src/Compilers/Core/Portable/Compilation/Compilation.cs
浏览文件 @
feb0866a
...
...
@@ -2908,7 +2908,16 @@ internal string GetMessage(ITypeSymbol source, ITypeSymbol destination)
public
abstract
IEnumerable
<
ISymbol
>
GetSymbolsWithName
(
Func
<
string
,
bool
>
predicate
,
SymbolFilter
filter
=
SymbolFilter
.
TypeAndMember
,
CancellationToken
cancellationToken
=
default
(
CancellationToken
));
/// <summary>
/// Return source declaration symbols whose name matches the provided name
/// Return true if there is a source declaration symbol name that matches the provided name.
/// This will be faster than <see cref="ContainsSymbolsWithName(Func{string, bool}, SymbolFilter, CancellationToken)"/>
/// when predicate is just a simple string check.
/// </summary>
internal
abstract
bool
ContainsSymbolsWithName
(
string
name
,
SymbolFilter
filter
=
SymbolFilter
.
TypeAndMember
,
CancellationToken
cancellationToken
=
default
(
CancellationToken
));
/// <summary>
/// Return source declaration symbols whose name matches the provided name. This will be
/// faster than <see cref="GetSymbolsWithName(Func{string, bool}, SymbolFilter, CancellationToken)"/>
/// when predicate is just a simple string check.
/// </summary>
internal
abstract
IEnumerable
<
ISymbol
>
GetSymbolsWithName
(
string
name
,
SymbolFilter
filter
=
SymbolFilter
.
TypeAndMember
,
CancellationToken
cancellationToken
=
default
(
CancellationToken
));
...
...
src/Compilers/VisualBasic/Portable/Compilation/VisualBasicCompilation.vb
浏览文件 @
feb0866a
...
...
@@ -2729,6 +2729,18 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
Return
New
PredicateSymbolSearcher
(
Me
,
filter
,
predicate
,
cancellationToken
).
GetSymbolsWithName
()
End
Function
Friend
Overrides
Function
ContainsSymbolsWithName
(
name
As
String
,
Optional
filter
As
SymbolFilter
=
SymbolFilter
.
TypeAndMember
,
Optional
cancellationToken
As
CancellationToken
=
Nothing
)
As
Boolean
If
name
Is
Nothing
Then
Throw
New
ArgumentNullException
(
NameOf
(
name
))
End
If
If
filter
=
SymbolFilter
.
None
Then
Throw
New
ArgumentException
(
VBResources
.
NoNoneSearchCriteria
,
NameOf
(
filter
))
End
If
Return
DeclarationTable
.
ContainsName
(
MergedRootDeclaration
,
name
,
filter
,
cancellationToken
)
End
Function
Friend
Overrides
Function
GetSymbolsWithName
(
name
As
String
,
Optional
filter
As
SymbolFilter
=
SymbolFilter
.
TypeAndMember
,
Optional
cancellationToken
As
CancellationToken
=
Nothing
)
As
IEnumerable
(
Of
ISymbol
)
If
name
Is
Nothing
Then
Throw
New
ArgumentNullException
(
NameOf
(
name
))
...
...
src/Compilers/VisualBasic/Portable/Declarations/DeclarationTable.vb
浏览文件 @
feb0866a
...
...
@@ -279,12 +279,49 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols
End
Get
End
Property
Public
Shared
Function
ContainsName
(
mergedRoot
As
MergedNamespaceDeclaration
,
name
As
String
,
filter
As
SymbolFilter
,
cancellationToken
As
CancellationToken
)
As
Boolean
Return
ContainsNameHelper
(
mergedRoot
,
Function
(
n
)
IdentifierComparison
.
Equals
(
n
,
name
),
filter
,
Function
(
t
)
t
.
MemberNames
.
Contains
(
name
),
cancellationToken
)
End
Function
Public
Shared
Function
ContainsName
(
mergedRoot
As
MergedNamespaceDeclaration
,
predicate
As
Func
(
Of
String
,
Boolean
),
filter
As
SymbolFilter
,
cancellationToken
As
CancellationToken
)
As
Boolean
Return
ContainsNameHelper
(
mergedRoot
,
predicate
,
filter
,
Function
(
t
)
For
Each
name
In
t
.
MemberNames
If
predicate
(
name
)
Then
Return
True
End
If
Next
Return
False
End
Function
,
cancellationToken
)
End
Function
Private
Shared
Function
ContainsNameHelper
(
mergedRoot
As
MergedNamespaceDeclaration
,
predicate
As
Func
(
Of
String
,
Boolean
),
filter
As
SymbolFilter
,
typePredicate
As
Func
(
Of
SingleTypeDeclaration
,
Boolean
),
cancellationToken
As
CancellationToken
)
As
Boolean
Dim
includeNamespace
=
(
filter
And
SymbolFilter
.
Namespace
)
=
SymbolFilter
.
Namespace
Dim
includeType
=
(
filter
And
SymbolFilter
.
Type
)
=
SymbolFilter
.
Type
Dim
includeMember
=
(
filter
And
SymbolFilter
.
Member
)
=
SymbolFilter
.
Member
...
...
@@ -311,22 +348,19 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols
If
includeMember
Then
Dim
mergedType
=
DirectCast
(
current
,
MergedTypeDeclaration
)
For
Each
name
In
mergedType
.
MemberName
s
If
predicate
(
nam
e
)
Then
For
Each
childType
In
mergedType
.
Declaration
s
If
typePredicate
(
childTyp
e
)
Then
Return
True
End
If
Next
End
If
End
If
For
Each
child
In
current
.
Children
.
OfType
(
Of
MergedNamespaceOrTypeDeclaration
)()
If
includeMember
OrElse
includeType
Then
stack
.
Push
(
child
)
Continue
For
End
If
For
Each
child
In
current
.
Children
Dim
childNamespaceOrType
=
DirectCast
(
child
,
MergedNamespaceOrTypeDeclaration
)
If
child
.
Kind
=
DeclarationKind
.
Namespace
Then
stack
.
Push
(
child
)
If
includeMember
OrElse
includeType
OrElse
childNamespaceOrType
.
Kind
=
DeclarationKind
.
Namespace
Then
stack
.
Push
(
child
NamespaceOrType
)
End
If
Next
End
While
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录