Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
64b98d70
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,发现更多精彩内容 >>
提交
64b98d70
编写于
7月 02, 2017
作者:
C
CyrusNajmabadi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Remove caching.
上级
6ff9e44f
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
64 addition
and
66 deletion
+64
-66
src/Workspaces/Core/Portable/PatternMatching/PatternMatcher.cs
...orkspaces/Core/Portable/PatternMatching/PatternMatcher.cs
+64
-66
未找到文件。
src/Workspaces/Core/Portable/PatternMatching/PatternMatcher.cs
浏览文件 @
64b98d70
...
@@ -30,14 +30,9 @@ internal abstract partial class PatternMatcher : IDisposable
...
@@ -30,14 +30,9 @@ internal abstract partial class PatternMatcher : IDisposable
public
const
int
CamelCaseMatchesFromStartBonus
=
2
;
public
const
int
CamelCaseMatchesFromStartBonus
=
2
;
public
const
int
CamelCaseMaxWeight
=
CamelCaseContiguousBonus
+
CamelCaseMatchesFromStartBonus
;
public
const
int
CamelCaseMaxWeight
=
CamelCaseContiguousBonus
+
CamelCaseMatchesFromStartBonus
;
private
readonly
object
_gate
=
new
object
();
private
readonly
bool
_includeMatchedSpans
;
private
readonly
bool
_includeMatchedSpans
;
private
readonly
bool
_allowFuzzyMatching
;
private
readonly
bool
_allowFuzzyMatching
;
private
readonly
Dictionary
<
string
,
StringBreaks
>
_stringToWordSpans
=
new
Dictionary
<
string
,
StringBreaks
>();
private
static
readonly
Func
<
string
,
StringBreaks
>
_breakIntoWordSpans
=
StringBreaker
.
BreakIntoWordParts
;
// PERF: Cache the culture's compareInfo to avoid the overhead of asking for them repeatedly in inner loops
// PERF: Cache the culture's compareInfo to avoid the overhead of asking for them repeatedly in inner loops
private
readonly
CompareInfo
_compareInfo
;
private
readonly
CompareInfo
_compareInfo
;
private
readonly
TextInfo
_textInfo
;
private
readonly
TextInfo
_textInfo
;
...
@@ -79,12 +74,6 @@ internal abstract partial class PatternMatcher : IDisposable
...
@@ -79,12 +74,6 @@ internal abstract partial class PatternMatcher : IDisposable
public
virtual
void
Dispose
()
public
virtual
void
Dispose
()
{
{
foreach
(
var
kvp
in
_stringToWordSpans
)
{
kvp
.
Value
.
Dispose
();
}
_stringToWordSpans
.
Clear
();
}
}
public
static
PatternMatcher
CreatePatternMatcher
(
public
static
PatternMatcher
CreatePatternMatcher
(
...
@@ -130,14 +119,6 @@ internal static (string name, string containerOpt) GetNameAndContainer(string pa
...
@@ -130,14 +119,6 @@ internal static (string name, string containerOpt) GetNameAndContainer(string pa
private
bool
SkipMatch
(
string
candidate
)
private
bool
SkipMatch
(
string
candidate
)
=>
_invalidPattern
||
string
.
IsNullOrWhiteSpace
(
candidate
);
=>
_invalidPattern
||
string
.
IsNullOrWhiteSpace
(
candidate
);
private
StringBreaks
GetCandidateHumps
(
string
word
)
{
lock
(
_gate
)
{
return
_stringToWordSpans
.
GetOrAdd
(
word
,
_breakIntoWordSpans
);
}
}
private
static
bool
ContainsUpperCaseLetter
(
string
pattern
)
private
static
bool
ContainsUpperCaseLetter
(
string
pattern
)
{
{
// Expansion of "foreach(char ch in pattern)" to avoid a CharEnumerator allocation
// Expansion of "foreach(char ch in pattern)" to avoid a CharEnumerator allocation
...
@@ -207,61 +188,79 @@ private static bool ContainsUpperCaseLetter(string pattern)
...
@@ -207,61 +188,79 @@ private static bool ContainsUpperCaseLetter(string pattern)
}
}
}
}
var
patternIsLowercase
=
patternChunk
.
IsLowercase
;
StringBreaks
?
candidateHumpsOpt
=
null
;
if
(
caseInsensitiveIndex
>
0
)
try
{
{
// We found the pattern somewhere in the candidate. This could be a substring match.
var
patternIsLowercase
=
patternChunk
.
IsLowercase
;
// However, we don't want to be overaggressive in returning just any substring results.
if
(
caseInsensitiveIndex
>
0
)
// So do a few more checks to make sure this is a good result.
if
(!
patternIsLowercase
)
{
{
//
Pattern contained uppercase letters. This is a strong indication from the
//
We found the pattern somewhere in the candidate. This could be a substring match.
//
user that they expect the same letters to be uppercase in the result. As
//
However, we don't want to be overaggressive in returning just any substring results.
//
such, only return this if we can find this pattern exactly in the candidate
.
//
So do a few more checks to make sure this is a good result
.
var
caseSensitiveIndex
=
_compareInfo
.
IndexOf
(
candidate
,
patternChunk
.
Text
);
if
(!
patternIsLowercase
)
if
(
caseSensitiveIndex
>
0
)
{
return
new
PatternMatch
(
PatternMatchKind
.
Substring
,
punctuationStripped
,
isCaseSensitive
:
true
,
matchedSpan
:
GetMatchedSpan
(
caseSensitiveIndex
,
patternChunk
.
Text
.
Length
));
}
}
else
{
// Pattern was all lowercase. This can lead to lots of false positives. For
// example, we don't want "bin" to match "CombineUnits". Instead, we want it
// to match "BinaryOperator". As such, make sure our match looks like it's
// starting an actual word in the candidate.
// Do a quick check to avoid the expensive work of having to go get the candidate
// humps.
if
(
char
.
IsUpper
(
candidate
[
caseInsensitiveIndex
]))
{
{
return
new
PatternMatch
(
PatternMatchKind
.
Substring
,
punctuationStripped
,
// Pattern contained uppercase letters. This is a strong indication from the
isCaseSensitive
:
false
,
// user that they expect the same letters to be uppercase in the result. As
matchedSpan
:
GetMatchedSpan
(
caseInsensitiveIndex
,
patternChunk
.
Text
.
Length
));
// such, only return this if we can find this pattern exactly in the candidate.
}
var
candidateHumps
=
GetCandidateHumps
(
candidate
);
var
caseSensitiveIndex
=
_compareInfo
.
IndexOf
(
candidate
,
patternChunk
.
Text
);
for
(
int
i
=
0
,
n
=
candidateHumps
.
GetCount
();
i
<
n
;
i
++)
if
(
caseSensitiveIndex
>
0
)
{
return
new
PatternMatch
(
PatternMatchKind
.
Substring
,
punctuationStripped
,
isCaseSensitive
:
true
,
matchedSpan
:
GetMatchedSpan
(
caseSensitiveIndex
,
patternChunk
.
Text
.
Length
));
}
}
else
{
{
var
hump
=
TextSpan
.
FromBounds
(
candidateHumps
[
i
].
Start
,
candidateLength
);
// Pattern was all lowercase. This can lead to lots of false positives. For
if
(
PartStartsWith
(
candidate
,
hump
,
patternChunk
.
Text
,
_ignoreCaseCompareOptions
))
// example, we don't want "bin" to match "CombineUnits". Instead, we want it
// to match "BinaryOperator". As such, make sure our match looks like it's
// starting an actual word in the candidate.
// Do a quick check to avoid the expensive work of having to go get the candidate
// humps.
if
(
char
.
IsUpper
(
candidate
[
caseInsensitiveIndex
]))
{
{
return
new
PatternMatch
(
PatternMatchKind
.
Substring
,
punctuationStripped
,
return
new
PatternMatch
(
PatternMatchKind
.
Substring
,
punctuationStripped
,
isCaseSensitive
:
PartStartsWith
(
candidate
,
hump
,
patternChunk
.
Text
,
_compareOptions
),
isCaseSensitive
:
false
,
matchedSpan
:
GetMatchedSpan
(
hump
.
Start
,
patternChunk
.
Text
.
Length
));
matchedSpan
:
GetMatchedSpan
(
caseInsensitiveIndex
,
patternChunk
.
Text
.
Length
));
}
var
candidateHumps
=
StringBreaker
.
BreakIntoWordParts
(
candidate
);
candidateHumpsOpt
=
candidateHumps
;
for
(
int
i
=
0
,
n
=
candidateHumps
.
GetCount
();
i
<
n
;
i
++)
{
var
hump
=
TextSpan
.
FromBounds
(
candidateHumps
[
i
].
Start
,
candidateLength
);
if
(
PartStartsWith
(
candidate
,
hump
,
patternChunk
.
Text
,
CompareOptions
.
IgnoreCase
))
{
return
new
PatternMatch
(
PatternMatchKind
.
Substring
,
punctuationStripped
,
isCaseSensitive
:
PartStartsWith
(
candidate
,
hump
,
patternChunk
.
Text
,
CompareOptions
.
None
),
matchedSpan
:
GetMatchedSpan
(
hump
.
Start
,
patternChunk
.
Text
.
Length
));
}
}
}
}
}
}
}
}
// Didn't have an exact/prefix match, or a high enough quality substring match.
// Didn't have an exact/prefix match, or a high enough quality substring match.
// See if we can find a camel case match.
// See if we can find a camel case match.
return
TryCamelCaseMatch
(
if
(
candidateHumpsOpt
==
null
)
candidate
,
patternChunk
,
punctuationStripped
,
patternIsLowercase
);
{
candidateHumpsOpt
=
StringBreaker
.
BreakIntoWordParts
(
candidate
);
}
return
TryCamelCaseMatch
(
candidate
,
patternChunk
,
punctuationStripped
,
patternIsLowercase
,
candidateHumpsOpt
.
Value
);
}
finally
{
if
(
candidateHumpsOpt
.
HasValue
)
{
candidateHumpsOpt
.
Value
.
Dispose
();
}
}
}
}
private
TextSpan
?
GetMatchedSpan
(
int
start
,
int
length
)
private
TextSpan
?
GetMatchedSpan
(
int
start
,
int
length
)
...
@@ -430,13 +429,13 @@ private bool PartStartsWith(string candidate, TextSpan candidatePart, string pat
...
@@ -430,13 +429,13 @@ private bool PartStartsWith(string candidate, TextSpan candidatePart, string pat
private
PatternMatch
?
TryCamelCaseMatch
(
private
PatternMatch
?
TryCamelCaseMatch
(
string
candidate
,
TextChunk
patternChunk
,
string
candidate
,
TextChunk
patternChunk
,
bool
punctuationStripped
,
bool
isLowercase
)
bool
punctuationStripped
,
bool
isLowercase
,
StringBreaks
candidateHumps
)
{
{
if
(
isLowercase
)
if
(
isLowercase
)
{
{
// e) If the word was entirely lowercase, then attempt a special lower cased camel cased
// e) If the word was entirely lowercase, then attempt a special lower cased camel cased
// match. i.e. cofipro would match CodeFixProvider.
// match. i.e. cofipro would match CodeFixProvider.
var
candidateHumps
=
GetCandidateHumps
(
candidate
);
var
camelCaseKind
=
TryAllLowerCamelCaseMatch
(
var
camelCaseKind
=
TryAllLowerCamelCaseMatch
(
candidate
,
candidateHumps
,
patternChunk
,
out
var
matchedSpans
);
candidate
,
candidateHumps
,
patternChunk
,
out
var
matchedSpans
);
if
(
camelCaseKind
.
HasValue
)
if
(
camelCaseKind
.
HasValue
)
...
@@ -452,8 +451,7 @@ private bool PartStartsWith(string candidate, TextSpan candidatePart, string pat
...
@@ -452,8 +451,7 @@ private bool PartStartsWith(string candidate, TextSpan candidatePart, string pat
// i.e. CoFiPro would match CodeFixProvider, but CofiPro would not.
// i.e. CoFiPro would match CodeFixProvider, but CofiPro would not.
if
(
patternChunk
.
PatternHumps
.
Count
>
0
)
if
(
patternChunk
.
PatternHumps
.
Count
>
0
)
{
{
var
candidateHumps
=
GetCandidateHumps
(
candidate
);
var
camelCaseKind
=
TryUpperCaseCamelCaseMatch
(
candidate
,
candidateHumps
,
patternChunk
,
CompareOptions
.
None
,
out
var
matchedSpans
);
var
camelCaseKind
=
TryUpperCaseCamelCaseMatch
(
candidate
,
candidateHumps
,
patternChunk
,
_compareOptions
,
out
var
matchedSpans
);
if
(
camelCaseKind
.
HasValue
)
if
(
camelCaseKind
.
HasValue
)
{
{
return
new
PatternMatch
(
return
new
PatternMatch
(
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录