Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
2d797bb9
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,发现更多精彩内容 >>
提交
2d797bb9
编写于
5月 17, 2016
作者:
T
Tomáš Matoušek
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix BlobBuilder.ToArray (#11376)
上级
ae75fe74
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
56 addition
and
13 deletion
+56
-13
src/Compilers/Core/CodeAnalysisTest/PEWriter/BlobTests.cs
src/Compilers/Core/CodeAnalysisTest/PEWriter/BlobTests.cs
+40
-1
src/Compilers/Core/Portable/PEWriter/BlobBuilder.cs
src/Compilers/Core/Portable/PEWriter/BlobBuilder.cs
+16
-12
未找到文件。
src/Compilers/Core/CodeAnalysisTest/PEWriter/BlobTests.cs
浏览文件 @
2d797bb9
...
...
@@ -183,8 +183,10 @@ public void GetChunks_DestructingEnum()
}
}
[
Fact
]
public
void
ToArray
()
public
void
ToArray
1
()
{
var
builder
=
new
BlobBuilder
(
16
);
...
...
@@ -222,6 +224,43 @@ public void ToArray()
AssertEx
.
Equal
(
new
byte
[]
{
0xdd
,
0xcc
,
0xbb
,
0xaa
},
builder
.
ToArray
(
13
,
4
));
}
[
Fact
]
public
void
ToArray2
()
{
var
builder
=
new
BlobBuilder
(
16
);
AssertEx
.
Equal
(
new
byte
[]
{
},
builder
.
ToArray
(
0
,
0
));
for
(
int
i
=
0
;
i
<
34
;
i
++)
{
builder
.
WriteByte
((
byte
)
i
);
}
AssertEx
.
Equal
(
new
byte
[]
{
0x00
,
0x01
,
0x02
,
0x03
,
0x04
,
0x05
,
0x06
,
0x07
,
0x08
,
0x09
,
0x0A
,
0x0B
,
0x0C
,
0x0D
,
0x0E
,
0x0F
,
0x10
,
0x11
,
0x12
,
0x13
,
0x14
,
0x15
,
0x16
,
0x17
,
0x18
,
0x19
,
0x1A
,
0x1B
,
0x1C
,
0x1D
,
0x1E
,
0x1F
,
0x20
,
0x21
},
builder
.
ToArray
());
AssertEx
.
Equal
(
new
byte
[]
{
0x0E
,
0x0F
,
0x10
,
0x11
,
0x12
,
0x13
,
0x14
,
0x15
,
0x16
,
0x17
,
0x18
,
0x19
,
0x1A
,
0x1B
,
0x1C
,
0x1D
,
0x1E
,
0x1F
,
0x20
,
0x21
},
builder
.
ToArray
(
0x0e
,
20
));
AssertEx
.
Equal
(
new
byte
[]
{
0x0E
},
builder
.
ToArray
(
0x0e
,
1
));
AssertEx
.
Equal
(
new
byte
[]
{
0x0E
,
0x0F
},
builder
.
ToArray
(
0x0e
,
2
));
AssertEx
.
Equal
(
new
byte
[]
{
0x0E
,
0x0F
,
0x10
},
builder
.
ToArray
(
0x0e
,
3
));
AssertEx
.
Equal
(
new
byte
[]
{
0x0E
,
0x0F
,
0x10
,
0x11
},
builder
.
ToArray
(
0x0e
,
4
));
AssertEx
.
Equal
(
new
byte
[]
{
0x1E
},
builder
.
ToArray
(
0x1e
,
1
));
AssertEx
.
Equal
(
new
byte
[]
{
0x1E
,
0x1F
},
builder
.
ToArray
(
0x1e
,
2
));
AssertEx
.
Equal
(
new
byte
[]
{
0x1E
,
0x1F
,
0x20
},
builder
.
ToArray
(
0x1e
,
3
));
AssertEx
.
Equal
(
new
byte
[]
{
0x1E
,
0x1F
,
0x20
,
0x21
},
builder
.
ToArray
(
0x1e
,
4
));
}
[
Fact
]
public
void
ToArray_Errors
()
{
...
...
src/Compilers/Core/Portable/PEWriter/BlobBuilder.cs
浏览文件 @
2d797bb9
...
...
@@ -279,29 +279,33 @@ public byte[] ToArray(int start, int byteCount)
var
result
=
new
byte
[
byteCount
];
int
chunkStartPosition
=
0
;
int
resultOffset
=
0
;
int
chunkStart
=
0
;
int
bufferStart
=
start
;
int
bufferEnd
=
start
+
byteCount
;
foreach
(
var
chunk
in
GetChunks
())
{
int
chunkEndPosition
=
chunkStartPosition
+
chunk
.
Length
;
int
chunkEnd
=
chunkStart
+
chunk
.
Length
;
Debug
.
Assert
(
bufferStart
>=
chunkStart
);
if
(
chunkEnd
Position
>
s
tart
)
if
(
chunkEnd
>
bufferS
tart
)
{
int
bytesToCopy
=
Math
.
Min
(
chunk
.
Length
,
result
.
Length
-
resultOffset
);
if
(
bytesToCopy
==
0
)
int
bytesToCopy
=
Math
.
Min
(
bufferEnd
,
chunkEnd
)
-
bufferStart
;
Debug
.
Assert
(
bytesToCopy
>=
0
);
Array
.
Copy
(
chunk
.
_buffer
,
bufferStart
-
chunkStart
,
result
,
bufferStart
-
start
,
bytesToCopy
);
bufferStart
+=
bytesToCopy
;
if
(
bufferStart
==
bufferEnd
)
{
break
;
}
Array
.
Copy
(
chunk
.
_buffer
,
Math
.
Max
(
start
-
chunkStartPosition
,
0
),
result
,
resultOffset
,
bytesToCopy
);
resultOffset
+=
bytesToCopy
;
}
chunkStart
Position
=
chunkEndPosition
;
chunkStart
=
chunkEnd
;
}
Debug
.
Assert
(
resultOffset
==
result
.
Length
);
Debug
.
Assert
(
bufferStart
==
bufferEnd
);
return
result
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录