Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
fefcc593
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,发现更多精彩内容 >>
提交
fefcc593
编写于
7月 11, 2017
作者:
C
CyrusNajmabadi
提交者:
GitHub
7月 11, 2017
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #20790 from CyrusNajmabadi/guidSerialization
Serialize a guid without an intermediary array allocation.
上级
858104b9
a5ca6ae9
变更
7
显示空白变更内容
内联
并排
Showing
7 changed file
with
59 addition
and
8 deletion
+59
-8
src/Compilers/Core/CodeAnalysisTest/ObjectSerializationTests.cs
...mpilers/Core/CodeAnalysisTest/ObjectSerializationTests.cs
+18
-0
src/Compilers/Core/Portable/Serialization/ObjectReader.cs
src/Compilers/Core/Portable/Serialization/ObjectReader.cs
+11
-0
src/Compilers/Core/Portable/Serialization/ObjectWriter.cs
src/Compilers/Core/Portable/Serialization/ObjectWriter.cs
+22
-0
src/Workspaces/Core/Portable/Execution/AbstractReferenceSerializationService.cs
...rtable/Execution/AbstractReferenceSerializationService.cs
+2
-2
src/Workspaces/Core/Portable/Workspace/Solution/DocumentId.cs
...Workspaces/Core/Portable/Workspace/Solution/DocumentId.cs
+2
-2
src/Workspaces/Core/Portable/Workspace/Solution/ProjectId.cs
src/Workspaces/Core/Portable/Workspace/Solution/ProjectId.cs
+2
-2
src/Workspaces/Core/Portable/Workspace/Solution/SolutionId.cs
...Workspaces/Core/Portable/Workspace/Solution/SolutionId.cs
+2
-2
未找到文件。
src/Compilers/Core/CodeAnalysisTest/ObjectSerializationTests.cs
浏览文件 @
fefcc593
...
...
@@ -1032,6 +1032,24 @@ private void TestRoundTripChar(Char ch)
TestRoundTrip
(
ch
,
(
w
,
v
)
=>
w
.
WriteChar
(
v
),
r
=>
r
.
ReadChar
());
}
[
Fact
]
public
void
TestRoundTripGuid
()
{
TestRoundTripGuid
(
Guid
.
Empty
);
TestRoundTripGuid
(
new
Guid
(
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
1
));
TestRoundTripGuid
(
new
Guid
(
0
b10000000000000000000000000000000
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
1
));
TestRoundTripGuid
(
new
Guid
(
0
b10000000000000000000000000000000
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
));
for
(
int
i
=
0
;
i
<
10
;
i
++)
{
TestRoundTripGuid
(
Guid
.
NewGuid
());
}
}
private
void
TestRoundTripGuid
(
Guid
guid
)
{
TestRoundTrip
(
guid
,
(
w
,
v
)
=>
w
.
WriteGuid
(
v
),
r
=>
r
.
ReadGuid
());
}
[
Fact
]
public
void
TestRoundTripStringCharacters
()
{
...
...
src/Compilers/Core/Portable/Serialization/ObjectReader.cs
浏览文件 @
fefcc593
...
...
@@ -124,6 +124,17 @@ public void Dispose()
public
ushort
ReadUInt16
()
=>
_reader
.
ReadUInt16
();
public
string
ReadString
()
=>
ReadStringValue
();
public
Guid
ReadGuid
()
{
var
accessor
=
new
ObjectWriter
.
GuidAccessor
{
Low64
=
ReadInt64
(),
High64
=
ReadInt64
()
};
return
accessor
.
Guid
;
}
public
object
ReadValue
()
{
var
oldDepth
=
_recursionDepth
;
...
...
src/Compilers/Core/Portable/Serialization/ObjectWriter.cs
浏览文件 @
fefcc593
...
...
@@ -119,6 +119,28 @@ public void Dispose()
public
void
WriteUInt16
(
ushort
value
)
=>
_writer
.
Write
(
value
);
public
void
WriteString
(
string
value
)
=>
WriteStringValue
(
value
);
/// <summary>
/// Used so we can easily grab the low/high 64bits of a guid for serialization.
/// </summary>
[
StructLayout
(
LayoutKind
.
Explicit
)]
internal
struct
GuidAccessor
{
[
FieldOffset
(
0
)]
public
Guid
Guid
;
[
FieldOffset
(
0
)]
public
long
Low64
;
[
FieldOffset
(
8
)]
public
long
High64
;
}
public
void
WriteGuid
(
Guid
guid
)
{
var
accessor
=
new
GuidAccessor
{
Guid
=
guid
};
WriteInt64
(
accessor
.
Low64
);
WriteInt64
(
accessor
.
High64
);
}
public
void
WriteValue
(
object
value
)
{
Debug
.
Assert
(
value
==
null
||
!
value
.
GetType
().
GetTypeInfo
().
IsEnum
,
"Enum should not be written with WriteValue. Write them as ints instead."
);
...
...
src/Workspaces/Core/Portable/Execution/AbstractReferenceSerializationService.cs
浏览文件 @
fefcc593
...
...
@@ -234,7 +234,7 @@ private void WriteAnalyzerFileReferenceMvid(AnalyzerFileReference reference, Obj
var
mvidHandle
=
metadataReader
.
GetModuleDefinition
().
Mvid
;
var
guid
=
metadataReader
.
GetGuid
(
mvidHandle
);
writer
.
Write
Value
(
guid
.
ToByteArray
()
);
writer
.
Write
Guid
(
guid
);
}
}
catch
...
...
@@ -312,7 +312,7 @@ private void WriteMvidTo(ModuleMetadata metadata, ObjectWriter writer, Cancellat
var
mvidHandle
=
metadataReader
.
GetModuleDefinition
().
Mvid
;
var
guid
=
metadataReader
.
GetGuid
(
mvidHandle
);
writer
.
Write
Value
(
guid
.
ToByteArray
()
);
writer
.
Write
Guid
(
guid
);
}
private
void
WritePortableExecutableReferenceTo
(
...
...
src/Workspaces/Core/Portable/Workspace/Solution/DocumentId.cs
浏览文件 @
fefcc593
...
...
@@ -102,7 +102,7 @@ void IObjectWritable.WriteTo(ObjectWriter writer)
{
ProjectId
.
WriteTo
(
writer
);
writer
.
Write
Value
(
Id
.
ToByteArray
()
);
writer
.
Write
Guid
(
Id
);
writer
.
WriteString
(
DebugName
);
}
...
...
@@ -110,7 +110,7 @@ internal static DocumentId ReadFrom(ObjectReader reader)
{
var
projectId
=
ProjectId
.
ReadFrom
(
reader
);
var
guid
=
new
Guid
((
byte
[])
reader
.
ReadValue
()
);
var
guid
=
reader
.
ReadGuid
(
);
var
debugName
=
reader
.
ReadString
();
return
CreateFromSerialized
(
projectId
,
guid
,
debugName
);
...
...
src/Workspaces/Core/Portable/Workspace/Solution/ProjectId.cs
浏览文件 @
fefcc593
...
...
@@ -86,13 +86,13 @@ public override int GetHashCode()
void
IObjectWritable
.
WriteTo
(
ObjectWriter
writer
)
{
writer
.
Write
Value
(
Id
.
ToByteArray
()
);
writer
.
Write
Guid
(
Id
);
writer
.
WriteString
(
DebugName
);
}
internal
static
ProjectId
ReadFrom
(
ObjectReader
reader
)
{
var
guid
=
new
Guid
((
byte
[])
reader
.
ReadValue
()
);
var
guid
=
reader
.
ReadGuid
(
);
var
debugName
=
reader
.
ReadString
();
return
CreateFromSerialized
(
guid
,
debugName
);
...
...
src/Workspaces/Core/Portable/Workspace/Solution/SolutionId.cs
浏览文件 @
fefcc593
...
...
@@ -83,13 +83,13 @@ public override int GetHashCode()
void
IObjectWritable
.
WriteTo
(
ObjectWriter
writer
)
{
writer
.
Write
Value
(
Id
.
ToByteArray
()
);
writer
.
Write
Guid
(
Id
);
writer
.
WriteString
(
DebugName
);
}
internal
static
SolutionId
ReadFrom
(
ObjectReader
reader
)
{
var
guid
=
new
Guid
((
byte
[])
reader
.
ReadValue
()
);
var
guid
=
reader
.
ReadGuid
(
);
var
debugName
=
reader
.
ReadString
();
return
CreateFromSerialized
(
guid
,
debugName
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录