Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
63ffc585
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,发现更多精彩内容 >>
提交
63ffc585
编写于
11月 30, 2017
作者:
S
Sam Harwell
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Avoid allocations in IsDefinedInSourceTree hot paths
Fixes #23462
上级
407d764e
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
35 addition
and
4 deletion
+35
-4
src/Compilers/CSharp/Portable/Symbols/Source/SourceMemberContainerSymbol.cs
...rp/Portable/Symbols/Source/SourceMemberContainerSymbol.cs
+25
-0
src/Compilers/CSharp/Portable/Symbols/Source/SourceNamespaceSymbol.cs
...s/CSharp/Portable/Symbols/Source/SourceNamespaceSymbol.cs
+4
-3
src/Compilers/CSharp/Portable/Syntax/NamespaceDeclarationSyntaxReference.cs
...rp/Portable/Syntax/NamespaceDeclarationSyntaxReference.cs
+6
-1
未找到文件。
src/Compilers/CSharp/Portable/Symbols/Source/SourceMemberContainerSymbol.cs
浏览文件 @
63ffc585
...
@@ -12,6 +12,7 @@
...
@@ -12,6 +12,7 @@
using
Microsoft.CodeAnalysis.CSharp.Symbols
;
using
Microsoft.CodeAnalysis.CSharp.Symbols
;
using
Microsoft.CodeAnalysis.CSharp.Syntax
;
using
Microsoft.CodeAnalysis.CSharp.Syntax
;
using
Microsoft.CodeAnalysis.PooledObjects
;
using
Microsoft.CodeAnalysis.PooledObjects
;
using
Microsoft.CodeAnalysis.Text
;
using
Roslyn.Utilities
;
using
Roslyn.Utilities
;
namespace
Microsoft.CodeAnalysis.CSharp.Symbols
namespace
Microsoft.CodeAnalysis.CSharp.Symbols
...
@@ -868,6 +869,30 @@ public override ImmutableArray<SyntaxReference> DeclaringSyntaxReferences
...
@@ -868,6 +869,30 @@ public override ImmutableArray<SyntaxReference> DeclaringSyntaxReferences
}
}
}
}
// This method behaves the same was as the base class, but avoids allocations associated with DeclaringSyntaxReferences
internal
override
bool
IsDefinedInSourceTree
(
SyntaxTree
tree
,
TextSpan
?
definedWithinSpan
,
CancellationToken
cancellationToken
)
{
var
declarations
=
declaration
.
Declarations
;
if
(
IsImplicitlyDeclared
&&
declarations
.
IsEmpty
)
{
return
ContainingSymbol
.
IsDefinedInSourceTree
(
tree
,
definedWithinSpan
,
cancellationToken
);
}
foreach
(
var
declaration
in
declarations
)
{
cancellationToken
.
ThrowIfCancellationRequested
();
var
syntaxRef
=
declaration
.
SyntaxReference
;
if
(
syntaxRef
.
SyntaxTree
==
tree
&&
(!
definedWithinSpan
.
HasValue
||
syntaxRef
.
Span
.
IntersectsWith
(
definedWithinSpan
.
Value
)))
{
return
true
;
}
}
return
false
;
}
#
endregion
#
endregion
#
region
Members
#
region
Members
...
...
src/Compilers/CSharp/Portable/Symbols/Source/SourceNamespaceSymbol.cs
浏览文件 @
63ffc585
...
@@ -463,11 +463,12 @@ internal override bool IsDefinedInSourceTree(SyntaxTree tree, TextSpan? definedW
...
@@ -463,11 +463,12 @@ internal override bool IsDefinedInSourceTree(SyntaxTree tree, TextSpan? definedW
}
}
// Check if any namespace declaration block intersects with the given tree/span.
// Check if any namespace declaration block intersects with the given tree/span.
foreach
(
var
syntaxRef
in
this
.
DeclaringSyntaxReference
s
)
foreach
(
var
declaration
in
_mergedDeclaration
.
Declaration
s
)
{
{
cancellationToken
.
ThrowIfCancellationRequested
();
cancellationToken
.
ThrowIfCancellationRequested
();
if
(
syntaxRef
.
SyntaxTree
!=
tree
)
var
declarationSyntaxRef
=
declaration
.
SyntaxReference
;
if
(
declarationSyntaxRef
.
SyntaxTree
!=
tree
)
{
{
continue
;
continue
;
}
}
...
@@ -477,7 +478,7 @@ internal override bool IsDefinedInSourceTree(SyntaxTree tree, TextSpan? definedW
...
@@ -477,7 +478,7 @@ internal override bool IsDefinedInSourceTree(SyntaxTree tree, TextSpan? definedW
return
true
;
return
true
;
}
}
var
syntax
=
syntaxRef
.
GetSyntax
(
cancellationToken
);
var
syntax
=
NamespaceDeclarationSyntaxReference
.
GetSyntax
(
declarationSyntaxRef
,
cancellationToken
);
if
(
syntax
.
FullSpan
.
IntersectsWith
(
definedWithinSpan
.
Value
))
if
(
syntax
.
FullSpan
.
IntersectsWith
(
definedWithinSpan
.
Value
))
{
{
return
true
;
return
true
;
...
...
src/Compilers/CSharp/Portable/Syntax/NamespaceDeclarationSyntaxReference.cs
浏览文件 @
63ffc585
...
@@ -2,8 +2,8 @@
...
@@ -2,8 +2,8 @@
using
System.Diagnostics
;
using
System.Diagnostics
;
using
System.Threading
;
using
System.Threading
;
using
Microsoft.CodeAnalysis.Syntax
;
using
Microsoft.CodeAnalysis.CSharp.Syntax
;
using
Microsoft.CodeAnalysis.CSharp.Syntax
;
using
Microsoft.CodeAnalysis.Syntax
;
namespace
Microsoft.CodeAnalysis.CSharp
namespace
Microsoft.CodeAnalysis.CSharp
{
{
...
@@ -19,6 +19,11 @@ public NamespaceDeclarationSyntaxReference(SyntaxReference reference)
...
@@ -19,6 +19,11 @@ public NamespaceDeclarationSyntaxReference(SyntaxReference reference)
}
}
protected
override
SyntaxNode
Translate
(
SyntaxReference
reference
,
CancellationToken
cancellationToken
)
protected
override
SyntaxNode
Translate
(
SyntaxReference
reference
,
CancellationToken
cancellationToken
)
{
return
GetSyntax
(
reference
,
cancellationToken
);
}
internal
static
SyntaxNode
GetSyntax
(
SyntaxReference
reference
,
CancellationToken
cancellationToken
)
{
{
var
node
=
(
CSharpSyntaxNode
)
reference
.
GetSyntax
(
cancellationToken
);
var
node
=
(
CSharpSyntaxNode
)
reference
.
GetSyntax
(
cancellationToken
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录