Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
155ce00d
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,发现更多精彩内容 >>
提交
155ce00d
编写于
8月 31, 2016
作者:
C
CyrusNajmabadi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Introduce a string slice abstraction.
上级
1d1725f1
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
250 addition
and
1 deletion
+250
-1
src/Compilers/Core/Portable/InternalUtilities/Hash.cs
src/Compilers/Core/Portable/InternalUtilities/Hash.cs
+13
-0
src/Workspaces/Core/Portable/Utilities/BKTree.Builder.cs
src/Workspaces/Core/Portable/Utilities/BKTree.Builder.cs
+7
-1
src/Workspaces/Core/Portable/Utilities/StringSlice.cs
src/Workspaces/Core/Portable/Utilities/StringSlice.cs
+229
-0
src/Workspaces/Core/Portable/Workspaces.csproj
src/Workspaces/Core/Portable/Workspaces.csproj
+1
-0
未找到文件。
src/Compilers/Core/Portable/InternalUtilities/Hash.cs
浏览文件 @
155ce00d
...
...
@@ -240,6 +240,19 @@ internal static int GetFNVHashCode(string text, int start, int length)
return
hashCode
;
}
internal
static
int
GetFNVHashCodeOrdinalIgnoreCase
(
string
text
,
int
start
,
int
length
)
{
int
hashCode
=
Hash
.
FnvOffsetBias
;
int
end
=
start
+
length
;
for
(
int
i
=
start
;
i
<
end
;
i
++)
{
hashCode
=
unchecked
((
hashCode
^
char
.
ToLowerInvariant
(
text
[
i
]))
*
Hash
.
FnvPrime
);
}
return
hashCode
;
}
/// <summary>
/// Compute the hashcode of a sub-string using FNV-1a
/// See http://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function
...
...
src/Workspaces/Core/Portable/Utilities/BKTree.Builder.cs
浏览文件 @
155ce00d
...
...
@@ -7,6 +7,7 @@
using
System.Linq
;
using
Microsoft.CodeAnalysis
;
using
Microsoft.CodeAnalysis.Text
;
using
Microsoft.CodeAnalysis.Utilities
;
namespace
Roslyn.Utilities
{
...
...
@@ -90,9 +91,14 @@ private class Builder
private
readonly
BuilderNode
[]
_builderNodes
;
public
Builder
(
IEnumerable
<
string
>
values
)
:
this
(
values
.
Select
(
v
=>
new
StringSlice
(
v
)))
{
}
public
Builder
(
IEnumerable
<
StringSlice
>
values
)
{
// TODO(cyrusn): Properly handle unicode normalization here.
var
distinctValues
=
values
.
Where
(
v
=>
v
.
Length
>
0
).
Distinct
(
CaseInsensitiveComparison
.
Comparer
).
ToArray
();
var
distinctValues
=
values
.
Where
(
v
=>
v
.
Length
>
0
).
Distinct
(
StringSliceComparer
.
OrdinalIgnoreCase
).
ToArray
();
var
charCount
=
values
.
Sum
(
v
=>
v
.
Length
);
_concatenatedLowerCaseWords
=
new
char
[
charCount
];
...
...
src/Workspaces/Core/Portable/Utilities/StringSlice.cs
0 → 100644
浏览文件 @
155ce00d
// 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
;
using
System.Collections.Generic
;
using
System.Diagnostics
;
using
Microsoft.CodeAnalysis.Text
;
using
Roslyn.Utilities
;
namespace
Microsoft.CodeAnalysis.Utilities
{
internal
struct
StringSlice
:
IEquatable
<
StringSlice
>
{
private
readonly
string
_underlyingString
;
private
readonly
TextSpan
_span
;
public
StringSlice
(
string
underlyingString
,
TextSpan
span
)
{
this
.
_underlyingString
=
underlyingString
;
this
.
_span
=
span
;
Debug
.
Assert
(
span
.
Start
>=
0
);
Debug
.
Assert
(
span
.
End
<=
underlyingString
.
Length
);
}
public
StringSlice
(
string
value
)
:
this
(
value
,
new
TextSpan
(
0
,
value
.
Length
))
{
}
private
bool
IsFullSlice
=>
this
.
_span
.
Start
==
0
&&
this
.
_span
.
Length
==
_underlyingString
.
Length
;
public
int
Length
=>
_span
.
Length
;
public
char
this
[
int
index
]
=>
_underlyingString
[
_span
.
Start
+
index
];
public
Enumerator
GetEnumerator
()
{
return
new
Enumerator
(
this
);
}
public
override
bool
Equals
(
object
obj
)
=>
Equals
((
StringSlice
)
obj
);
public
bool
Equals
(
StringSlice
other
)
{
return
EqualsOrdinal
(
other
);
}
internal
bool
EqualsOrdinal
(
StringSlice
other
)
{
if
(
this
.
IsFullSlice
&&
other
.
IsFullSlice
)
{
return
StringComparer
.
Ordinal
.
Equals
(
this
.
_underlyingString
,
other
.
_underlyingString
);
}
if
(
this
.
_span
.
Length
!=
other
.
_span
.
Length
)
{
return
false
;
}
var
end
=
this
.
_span
.
End
;
for
(
int
i
=
this
.
_span
.
Start
,
j
=
other
.
_span
.
Start
;
i
<
end
;
i
++,
j
++)
{
if
(
this
.
_underlyingString
[
i
]
!=
other
.
_underlyingString
[
j
])
{
return
false
;
}
}
return
true
;
}
internal
bool
EqualsOrdinalIgnoreCase
(
StringSlice
other
)
{
if
(
this
.
IsFullSlice
&&
other
.
IsFullSlice
)
{
return
StringComparer
.
OrdinalIgnoreCase
.
Equals
(
this
.
_underlyingString
,
other
.
_underlyingString
);
}
if
(
this
.
_span
.
Length
!=
other
.
_span
.
Length
)
{
return
false
;
}
var
end
=
this
.
_span
.
End
;
for
(
int
i
=
this
.
_span
.
Start
,
j
=
other
.
_span
.
Start
;
i
<
end
;
i
++,
j
++)
{
if
(
char
.
ToLowerInvariant
(
this
.
_underlyingString
[
i
])
!=
char
.
ToLowerInvariant
(
other
.
_underlyingString
[
j
]))
{
return
false
;
}
}
return
true
;
}
public
override
int
GetHashCode
()
{
return
GetHashCodeOrdinal
();
}
internal
int
GetHashCodeOrdinal
()
{
return
Hash
.
GetFNVHashCode
(
this
.
_underlyingString
,
this
.
_span
.
Start
,
this
.
_span
.
Length
);
}
internal
int
GetHashCodeOrdinalIgnoreCase
()
{
return
Hash
.
GetFNVHashCodeOrdinalIgnoreCase
(
this
.
_underlyingString
,
this
.
_span
.
Start
,
this
.
_span
.
Length
);
}
internal
int
CompareToOrdinal
(
StringSlice
other
)
{
if
(
this
.
IsFullSlice
&&
other
.
IsFullSlice
)
{
return
StringComparer
.
Ordinal
.
Compare
(
this
.
_underlyingString
,
other
.
_underlyingString
);
}
var
thisEnd
=
this
.
_span
.
End
;
var
otherEnd
=
other
.
_span
.
End
;
for
(
int
i
=
this
.
_span
.
Start
,
j
=
other
.
_span
.
Start
;
i
<
thisEnd
&&
j
<
otherEnd
;
i
++,
j
++)
{
var
diff
=
this
.
_underlyingString
[
i
]
-
other
.
_underlyingString
[
j
];
if
(
diff
!=
0
)
{
return
diff
;
}
}
// Choose the one that is shorter if their prefixes match so far.
return
this
.
Length
-
other
.
Length
;
}
internal
int
CompareToOrdinalIgnoreCase
(
StringSlice
other
)
{
if
(
this
.
IsFullSlice
&&
other
.
IsFullSlice
)
{
return
StringComparer
.
OrdinalIgnoreCase
.
Compare
(
this
.
_underlyingString
,
other
.
_underlyingString
);
}
var
thisEnd
=
this
.
_span
.
End
;
var
otherEnd
=
other
.
_span
.
End
;
for
(
int
i
=
this
.
_span
.
Start
,
j
=
other
.
_span
.
Start
;
i
<
thisEnd
&&
j
<
otherEnd
;
i
++,
j
++)
{
var
diff
=
char
.
ToLowerInvariant
(
this
.
_underlyingString
[
i
])
-
char
.
ToLowerInvariant
(
other
.
_underlyingString
[
j
]);
if
(
diff
!=
0
)
{
return
diff
;
}
}
// Choose the one that is shorter if their prefixes match so far.
return
this
.
Length
-
other
.
Length
;
}
public
struct
Enumerator
{
private
readonly
StringSlice
_stringSlice
;
private
int
index
;
public
Enumerator
(
StringSlice
stringSlice
)
{
_stringSlice
=
stringSlice
;
index
=
-
1
;
}
public
bool
MoveNext
()
{
index
++;
return
index
<
_stringSlice
.
Length
;
}
public
char
Current
=>
_stringSlice
[
index
];
}
}
internal
abstract
class
StringSliceComparer
:
IComparer
<
StringSlice
>,
IEqualityComparer
<
StringSlice
>
{
public
static
readonly
StringSliceComparer
Ordinal
=
new
OrdinalComparer
();
public
static
readonly
StringSliceComparer
OrdinalIgnoreCase
=
new
OrdinalIgnoreCaseComparer
();
private
class
OrdinalComparer
:
StringSliceComparer
{
public
override
int
Compare
(
StringSlice
x
,
StringSlice
y
)
{
return
x
.
CompareToOrdinal
(
y
);
}
public
override
bool
Equals
(
StringSlice
x
,
StringSlice
y
)
{
return
x
.
EqualsOrdinal
(
y
);
}
public
override
int
GetHashCode
(
StringSlice
obj
)
{
return
obj
.
GetHashCodeOrdinal
();
}
}
private
class
OrdinalIgnoreCaseComparer
:
StringSliceComparer
{
public
override
int
Compare
(
StringSlice
x
,
StringSlice
y
)
{
return
x
.
CompareToOrdinalIgnoreCase
(
y
);
}
public
override
bool
Equals
(
StringSlice
x
,
StringSlice
y
)
{
return
x
.
EqualsOrdinalIgnoreCase
(
y
);
}
public
override
int
GetHashCode
(
StringSlice
obj
)
{
return
obj
.
GetHashCodeOrdinalIgnoreCase
();
}
}
public
abstract
int
Compare
(
StringSlice
x
,
StringSlice
y
);
public
abstract
bool
Equals
(
StringSlice
x
,
StringSlice
y
);
public
abstract
int
GetHashCode
(
StringSlice
obj
);
}
}
\ No newline at end of file
src/Workspaces/Core/Portable/Workspaces.csproj
浏览文件 @
155ce00d
...
...
@@ -542,6 +542,7 @@
<Compile
Include=
"Utilities\ParameterName.cs"
/>
<Compile
Include=
"Utilities\SpellChecker.cs"
/>
<Compile
Include=
"Utilities\StringEscapeEncoder.cs"
/>
<Compile
Include=
"Utilities\StringSlice.cs"
/>
<Compile
Include=
"Utilities\ValuesSources\CachedWeakValueSource.cs"
/>
<Compile
Include=
"Utilities\WeakEventHandler.cs"
/>
<Compile
Include=
"Versions\Extensions.cs"
/>
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录