Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
0295cc78
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,发现更多精彩内容 >>
提交
0295cc78
编写于
3月 16, 2015
作者:
P
Paul Harrington
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
PERF: Avoid byte[] allocations in StringHeap
上级
9a281010
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
42 addition
and
8 deletion
+42
-8
src/Compilers/Core/Portable/PEWriter/BinaryWriter.cs
src/Compilers/Core/Portable/PEWriter/BinaryWriter.cs
+40
-3
src/Compilers/Core/Portable/PEWriter/MetadataHeapsBuilder.cs
src/Compilers/Core/Portable/PEWriter/MetadataHeapsBuilder.cs
+2
-5
未找到文件。
src/Compilers/Core/Portable/PEWriter/BinaryWriter.cs
浏览文件 @
0295cc78
...
...
@@ -4,6 +4,7 @@
using
System.Collections.Immutable
;
using
System.Diagnostics
;
using
System.Reflection
;
using
System.Text
;
namespace
Microsoft.Cci
{
...
...
@@ -74,12 +75,17 @@ internal void WriteSbyte(sbyte value)
internal
void
WriteBytes
(
byte
[]
buffer
)
{
if
(
buffer
==
null
)
WriteBytes
(
buffer
,
0
,
buffer
.
Length
);
}
internal
void
WriteBytes
(
byte
[]
buffer
,
int
offset
,
int
count
)
{
if
(
buffer
==
null
||
count
==
0
)
{
return
;
}
this
.
BaseStream
.
Write
(
buffer
,
0
,
buffer
.
Length
);
this
.
BaseStream
.
Write
(
buffer
,
offset
,
count
);
}
internal
void
WriteBytes
(
ImmutableArray
<
byte
>
buffer
)
...
...
@@ -119,7 +125,7 @@ internal void WriteChars(char[] chars)
return
;
}
Debug
.
Assert
(!
_utf8
,
"WriteChars has a problem with unmatche
s
surrogate pairs and does not support writing utf8"
);
Debug
.
Assert
(!
_utf8
,
"WriteChars has a problem with unmatche
d
surrogate pairs and does not support writing utf8"
);
MemoryStream
m
=
this
.
BaseStream
;
uint
i
=
m
.
Position
;
...
...
@@ -137,6 +143,29 @@ internal void WriteChars(char[] chars)
}
}
internal
void
WriteStringUtf16LE
(
string
str
)
{
if
(
str
==
null
)
{
return
;
}
MemoryStream
m
=
this
.
BaseStream
;
uint
i
=
m
.
Position
;
m
.
Position
=
i
+
(
uint
)
str
.
Length
*
2
;
byte
[]
buffer
=
m
.
Buffer
;
for
(
int
j
=
0
;
j
<
str
.
Length
;
j
++,
i
+=
2
)
{
char
ch
=
str
[
j
];
unchecked
{
buffer
[
i
]
=
(
byte
)
ch
;
buffer
[
i
+
1
]
=
(
byte
)(
ch
>>
8
);
}
}
}
internal
unsafe
void
WriteDouble
(
double
value
)
{
MemoryStream
m
=
this
.
BaseStream
;
...
...
@@ -405,6 +434,14 @@ internal void WriteString(string str, bool emitNullTerminator)
}
}
internal
void
WriteString
(
string
str
,
Encoding
encoding
)
{
MemoryStream
m
=
this
.
BaseStream
;
uint
i
=
m
.
Position
;
m
.
Position
=
i
+
(
uint
)
encoding
.
GetByteCount
(
str
);
encoding
.
GetBytes
(
str
,
0
,
str
.
Length
,
m
.
Buffer
,
(
int
)
i
);
}
/// <summary>
/// Implements compressed signed integer encoding as defined by ECMA-335-II chapter 23.2: Blobs and signatures.
/// </summary>
...
...
src/Compilers/Core/Portable/PEWriter/MetadataHeapsBuilder.cs
浏览文件 @
0295cc78
...
...
@@ -208,7 +208,7 @@ public uint GetUserStringToken(string str)
index
=
_userStringWriter
.
BaseStream
.
Position
+
(
uint
)
_userStringIndexStartOffset
;
_userStringIndex
.
Add
(
str
,
index
);
_userStringWriter
.
WriteCompressedUInt
((
uint
)
str
.
Length
*
2
+
1
);
_userStringWriter
.
Write
Chars
(
str
.
ToCharArray
()
);
_userStringWriter
.
Write
StringUtf16LE
(
str
);
// Write out a trailing byte indicating if the string is really quite simple
byte
stringKind
=
0
;
...
...
@@ -315,10 +315,7 @@ private void SerializeStringHeap()
else
{
_stringIndexMap
[
cur
.
Value
.
VirtIdx
]
=
position
;
// TODO (tomat): consider reusing the buffer instead of allocating a new one for each string
_stringWriter
.
WriteBytes
(
s_utf8Encoding
.
GetBytes
(
cur
.
Key
));
_stringWriter
.
WriteString
(
cur
.
Key
,
s_utf8Encoding
);
_stringWriter
.
WriteByte
(
0
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录