Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
af178ee2
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,发现更多精彩内容 >>
提交
af178ee2
编写于
11月 28, 2017
作者:
C
Cyrus Najmabadi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Reduce Location allocations while running analyzers.
上级
32bc937e
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
18 addition
and
16 deletion
+18
-16
src/Compilers/Core/Portable/DiagnosticAnalyzer/AnalyzerDriver.cs
...pilers/Core/Portable/DiagnosticAnalyzer/AnalyzerDriver.cs
+10
-10
src/Compilers/Core/Portable/DiagnosticAnalyzer/AnalyzerExecutor.cs
...lers/Core/Portable/DiagnosticAnalyzer/AnalyzerExecutor.cs
+8
-6
未找到文件。
src/Compilers/Core/Portable/DiagnosticAnalyzer/AnalyzerDriver.cs
浏览文件 @
af178ee2
...
...
@@ -8,9 +8,10 @@
using
System.Runtime.InteropServices
;
using
System.Threading
;
using
System.Threading.Tasks
;
using
Microsoft.CodeAnalysis.Operations
;
using
Microsoft.CodeAnalysis.Diagnostics.Telemetry
;
using
Microsoft.CodeAnalysis.Operations
;
using
Microsoft.CodeAnalysis.PooledObjects
;
using
Microsoft.CodeAnalysis.Text
;
using
Roslyn.Utilities
;
namespace
Microsoft.CodeAnalysis.Diagnostics
...
...
@@ -613,7 +614,7 @@ private bool IsInGeneratedCode(Location location, Compilation compilation, Cance
}
// Check if this is a generated code location.
if
(
IsGeneratedOrHiddenCodeLocation
(
location
))
if
(
IsGeneratedOrHiddenCodeLocation
(
location
.
SourceTree
,
location
.
SourceSpan
))
{
return
true
;
}
...
...
@@ -1275,7 +1276,7 @@ private bool IsGeneratedCodeSymbol(ISymbol symbol)
foreach
(
var
declaringRef
in
symbol
.
DeclaringSyntaxReferences
)
{
if
(!
IsGeneratedOrHiddenCodeLocation
(
declaringRef
.
GetLocation
()
))
if
(!
IsGeneratedOrHiddenCodeLocation
(
declaringRef
.
SyntaxTree
,
declaringRef
.
Span
))
{
return
false
;
}
...
...
@@ -1309,13 +1310,12 @@ protected bool IsGeneratedCode(SyntaxTree tree)
protected
bool
DoNotAnalyzeGeneratedCode
=>
_doNotAnalyzeGeneratedCode
;
// Location is in generated code if either the containing tree is a generated code file OR if it is a hidden source location.
protected
bool
IsGeneratedOrHiddenCodeLocation
(
Location
location
)
=>
IsGeneratedCode
(
location
.
SourceTree
)
||
IsHiddenSourceLocation
(
locatio
n
);
protected
bool
IsGeneratedOrHiddenCodeLocation
(
SyntaxTree
syntaxTree
,
TextSpan
span
)
=>
IsGeneratedCode
(
syntaxTree
)
||
IsHiddenSourceLocation
(
syntaxTree
,
spa
n
);
protected
bool
IsHiddenSourceLocation
(
Location
location
)
=>
location
.
IsInSource
&&
HasHiddenRegions
(
location
.
SourceTree
)
&&
location
.
SourceTree
.
IsHiddenPosition
(
location
.
SourceSpan
.
Start
);
protected
bool
IsHiddenSourceLocation
(
SyntaxTree
syntaxTree
,
TextSpan
span
)
=>
HasHiddenRegions
(
syntaxTree
)
&&
syntaxTree
.
IsHiddenPosition
(
span
.
Start
);
private
bool
HasHiddenRegions
(
SyntaxTree
tree
)
{
...
...
@@ -1630,7 +1630,7 @@ private bool ShouldExecuteOperationBlockActions(AnalysisScope analysisScope, ISy
continue
;
}
var
isInGeneratedCode
=
isGeneratedCodeSymbol
||
IsGeneratedOrHiddenCodeLocation
(
decl
.
GetLocation
()
);
var
isInGeneratedCode
=
isGeneratedCodeSymbol
||
IsGeneratedOrHiddenCodeLocation
(
decl
.
SyntaxTree
,
decl
.
Span
);
if
(
isInGeneratedCode
&&
DoNotAnalyzeGeneratedCode
)
{
analysisStateOpt
?.
MarkDeclarationComplete
(
symbol
,
i
,
analysisScope
.
Analyzers
);
...
...
src/Compilers/Core/Portable/DiagnosticAnalyzer/AnalyzerExecutor.cs
浏览文件 @
af178ee2
...
...
@@ -42,7 +42,7 @@ internal class AnalyzerExecutor
private
readonly
Func
<
DiagnosticAnalyzer
,
object
>
_getAnalyzerGateOpt
;
private
readonly
Func
<
DiagnosticAnalyzer
,
bool
>
_shouldSkipAnalysisOnGeneratedCode
;
private
readonly
Func
<
Diagnostic
,
DiagnosticAnalyzer
,
Compilation
,
CancellationToken
,
bool
>
_shouldSuppressGeneratedCodeDiagnostic
;
private
readonly
Func
<
Locatio
n
,
bool
>
_isGeneratedCodeLocation
;
private
readonly
Func
<
SyntaxTree
,
TextSpa
n
,
bool
>
_isGeneratedCodeLocation
;
private
readonly
ConcurrentDictionary
<
DiagnosticAnalyzer
,
TimeSpan
>
_analyzerExecutionTimeMapOpt
;
private
readonly
CompilationAnalysisValueProviderFactory
_compilationAnalysisValueProviderFactory
;
private
readonly
CancellationToken
_cancellationToken
;
...
...
@@ -86,7 +86,7 @@ internal class AnalyzerExecutor
AnalyzerManager
analyzerManager
,
Func
<
DiagnosticAnalyzer
,
bool
>
shouldSkipAnalysisOnGeneratedCode
,
Func
<
Diagnostic
,
DiagnosticAnalyzer
,
Compilation
,
CancellationToken
,
bool
>
shouldSuppressGeneratedCodeDiagnostic
,
Func
<
Locatio
n
,
bool
>
isGeneratedCodeLocation
,
Func
<
SyntaxTree
,
TextSpa
n
,
bool
>
isGeneratedCodeLocation
,
Func
<
DiagnosticAnalyzer
,
object
>
getAnalyzerGate
,
bool
logExecutionTime
=
false
,
Action
<
Diagnostic
,
DiagnosticAnalyzer
,
bool
>
addCategorizedLocalDiagnosticOpt
=
null
,
...
...
@@ -125,7 +125,7 @@ internal class AnalyzerExecutor
isCompilerAnalyzer
:
null
,
shouldSkipAnalysisOnGeneratedCode
:
_
=>
false
,
shouldSuppressGeneratedCodeDiagnostic
:
(
diagnostic
,
analyzer
,
compilation
,
ct
)
=>
false
,
isGeneratedCodeLocation
:
_
=>
false
,
isGeneratedCodeLocation
:
(
_1
,
_2
)
=>
false
,
getAnalyzerGateOpt
:
null
,
onAnalyzerException
:
onAnalyzerException
,
analyzerExceptionFilter
:
null
,
...
...
@@ -146,7 +146,7 @@ internal class AnalyzerExecutor
AnalyzerManager
analyzerManager
,
Func
<
DiagnosticAnalyzer
,
bool
>
shouldSkipAnalysisOnGeneratedCode
,
Func
<
Diagnostic
,
DiagnosticAnalyzer
,
Compilation
,
CancellationToken
,
bool
>
shouldSuppressGeneratedCodeDiagnostic
,
Func
<
Locatio
n
,
bool
>
isGeneratedCodeLocation
,
Func
<
SyntaxTree
,
TextSpa
n
,
bool
>
isGeneratedCodeLocation
,
Func
<
DiagnosticAnalyzer
,
object
>
getAnalyzerGateOpt
,
ConcurrentDictionary
<
DiagnosticAnalyzer
,
TimeSpan
>
analyzerExecutionTimeMapOpt
,
Action
<
Diagnostic
,
DiagnosticAnalyzer
,
bool
>
addCategorizedLocalDiagnosticOpt
,
...
...
@@ -1488,7 +1488,8 @@ private bool ShouldExecuteNode(SyntaxNodeAnalyzerStateData analyzerStateOpt, Syn
}
// Check if the node is generated code that must be skipped.
if
(
_shouldSkipAnalysisOnGeneratedCode
(
analyzer
)
&&
_isGeneratedCodeLocation
(
node
.
GetLocation
()))
if
(
_shouldSkipAnalysisOnGeneratedCode
(
analyzer
)
&&
_isGeneratedCodeLocation
(
node
.
SyntaxTree
,
node
.
Span
))
{
return
false
;
}
...
...
@@ -1505,7 +1506,8 @@ private bool ShouldExecuteOperation(OperationAnalyzerStateData analyzerStateOpt,
}
// Check if the operation syntax is generated code that must be skipped.
if
(
operation
.
Syntax
!=
null
&&
_shouldSkipAnalysisOnGeneratedCode
(
analyzer
)
&&
_isGeneratedCodeLocation
(
operation
.
Syntax
.
GetLocation
()))
if
(
operation
.
Syntax
!=
null
&&
_shouldSkipAnalysisOnGeneratedCode
(
analyzer
)
&&
_isGeneratedCodeLocation
(
operation
.
Syntax
.
SyntaxTree
,
operation
.
Syntax
.
Span
))
{
return
false
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录