Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
dotNET Platform
runtime
提交
ef9e276c
R
runtime
项目概览
dotNET Platform
/
runtime
12 个月 前同步成功
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
runtime
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
ef9e276c
编写于
6月 11, 2021
作者:
E
Elinor Fung
提交者:
GitHub
6月 11, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Make some Brotli p/invokes blittable (#54029)
* Make some Brotli p/invokes blittable * Use Interop.BOOL
上级
9ac357df
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
15 addition
and
13 deletion
+15
-13
src/libraries/Common/src/Interop/Interop.Brotli.cs
src/libraries/Common/src/Interop/Interop.Brotli.cs
+6
-6
src/libraries/System.IO.Compression.Brotli/src/System.IO.Compression.Brotli.csproj
...ompression.Brotli/src/System.IO.Compression.Brotli.csproj
+2
-0
src/libraries/System.IO.Compression.Brotli/src/System/IO/Compression/dec/BrotliDecoder.cs
...ion.Brotli/src/System/IO/Compression/dec/BrotliDecoder.cs
+2
-2
src/libraries/System.IO.Compression.Brotli/src/System/IO/Compression/enc/BrotliEncoder.cs
...ion.Brotli/src/System/IO/Compression/enc/BrotliEncoder.cs
+5
-5
未找到文件。
src/libraries/Common/src/Interop/Interop.Brotli.cs
浏览文件 @
ef9e276c
...
...
@@ -19,32 +19,32 @@ internal static class Brotli
ref
nuint
availableOut
,
byte
**
nextOut
,
out
nuint
totalOut
);
[
DllImport
(
Libraries
.
CompressionNative
)]
internal
static
extern
unsafe
bool
BrotliDecoderDecompress
(
nuint
availableInput
,
byte
*
inBytes
,
ref
nuint
availableOutput
,
byte
*
outBytes
);
internal
static
extern
unsafe
BOOL
BrotliDecoderDecompress
(
nuint
availableInput
,
byte
*
inBytes
,
nuint
*
availableOutput
,
byte
*
outBytes
);
[
DllImport
(
Libraries
.
CompressionNative
)]
internal
static
extern
void
BrotliDecoderDestroyInstance
(
IntPtr
state
);
[
DllImport
(
Libraries
.
CompressionNative
)]
internal
static
extern
bool
BrotliDecoderIsFinished
(
SafeBrotliDecoderHandle
state
);
internal
static
extern
BOOL
BrotliDecoderIsFinished
(
SafeBrotliDecoderHandle
state
);
[
DllImport
(
Libraries
.
CompressionNative
)]
internal
static
extern
SafeBrotliEncoderHandle
BrotliEncoderCreateInstance
(
IntPtr
allocFunc
,
IntPtr
freeFunc
,
IntPtr
opaque
);
[
DllImport
(
Libraries
.
CompressionNative
)]
internal
static
extern
bool
BrotliEncoderSetParameter
(
SafeBrotliEncoderHandle
state
,
BrotliEncoderParameter
parameter
,
uint
value
);
internal
static
extern
BOOL
BrotliEncoderSetParameter
(
SafeBrotliEncoderHandle
state
,
BrotliEncoderParameter
parameter
,
uint
value
);
[
DllImport
(
Libraries
.
CompressionNative
)]
internal
static
extern
unsafe
bool
BrotliEncoderCompressStream
(
internal
static
extern
unsafe
BOOL
BrotliEncoderCompressStream
(
SafeBrotliEncoderHandle
state
,
BrotliEncoderOperation
op
,
ref
nuint
availableIn
,
byte
**
nextIn
,
ref
nuint
availableOut
,
byte
**
nextOut
,
out
nuint
totalOut
);
[
DllImport
(
Libraries
.
CompressionNative
)]
internal
static
extern
bool
BrotliEncoderHasMoreOutput
(
SafeBrotliEncoderHandle
state
);
internal
static
extern
BOOL
BrotliEncoderHasMoreOutput
(
SafeBrotliEncoderHandle
state
);
[
DllImport
(
Libraries
.
CompressionNative
)]
internal
static
extern
void
BrotliEncoderDestroyInstance
(
IntPtr
state
);
[
DllImport
(
Libraries
.
CompressionNative
)]
internal
static
extern
unsafe
bool
BrotliEncoderCompress
(
int
quality
,
int
window
,
int
v
,
nuint
availableInput
,
byte
*
inBytes
,
ref
nuint
availableOutput
,
byte
*
outBytes
);
internal
static
extern
unsafe
BOOL
BrotliEncoderCompress
(
int
quality
,
int
window
,
int
v
,
nuint
availableInput
,
byte
*
inBytes
,
nuint
*
availableOutput
,
byte
*
outBytes
);
}
}
src/libraries/System.IO.Compression.Brotli/src/System.IO.Compression.Brotli.csproj
浏览文件 @
ef9e276c
...
...
@@ -11,6 +11,8 @@
</PropertyGroup>
<ItemGroup Condition="'$(TargetsAnyOS)' != 'true'">
<Compile Include="$(CommonPath)Interop\Interop.Brotli.cs" />
<!-- The native compression lib uses a BROTLI_BOOL type analogous to the Windows BOOL type -->
<Compile Include="$(CommonPath)Interop\Windows\Interop.BOOL.cs" />
<Compile Include="System\IO\Compression\enc\BrotliStream.Compress.cs" />
<Compile Include="System\IO\Compression\dec\BrotliStream.Decompress.cs" />
<Compile Include="System\IO\Compression\BrotliUtils.cs" />
...
...
src/libraries/System.IO.Compression.Brotli/src/System/IO/Compression/dec/BrotliDecoder.cs
浏览文件 @
ef9e276c
...
...
@@ -59,7 +59,7 @@ public OperationStatus Decompress(ReadOnlySpan<byte> source, Span<byte> destinat
bytesConsumed
=
0
;
bytesWritten
=
0
;
if
(
Interop
.
Brotli
.
BrotliDecoderIsFinished
(
_state
))
if
(
Interop
.
Brotli
.
BrotliDecoderIsFinished
(
_state
)
!=
Interop
.
BOOL
.
FALSE
)
return
OperationStatus
.
Done
;
nuint
availableOutput
=
(
nuint
)
destination
.
Length
;
nuint
availableInput
=
(
nuint
)
source
.
Length
;
...
...
@@ -117,7 +117,7 @@ public static unsafe bool TryDecompress(ReadOnlySpan<byte> source, Span<byte> de
fixed
(
byte
*
outBytes
=
&
MemoryMarshal
.
GetReference
(
destination
))
{
nuint
availableOutput
=
(
nuint
)
destination
.
Length
;
bool
success
=
Interop
.
Brotli
.
BrotliDecoderDecompress
((
nuint
)
source
.
Length
,
inBytes
,
ref
availableOutput
,
outBytes
)
;
bool
success
=
Interop
.
Brotli
.
BrotliDecoderDecompress
((
nuint
)
source
.
Length
,
inBytes
,
&
availableOutput
,
outBytes
)
!=
Interop
.
BOOL
.
FALSE
;
Debug
.
Assert
(
success
?
availableOutput
<=
(
nuint
)
destination
.
Length
:
availableOutput
==
0
);
...
...
src/libraries/System.IO.Compression.Brotli/src/System/IO/Compression/enc/BrotliEncoder.cs
浏览文件 @
ef9e276c
...
...
@@ -78,7 +78,7 @@ internal void SetQuality(int quality)
{
throw
new
ArgumentOutOfRangeException
(
nameof
(
quality
),
SR
.
Format
(
SR
.
BrotliEncoder_Quality
,
quality
,
0
,
BrotliUtils
.
Quality_Max
));
}
if
(
!
Interop
.
Brotli
.
BrotliEncoderSetParameter
(
_state
,
BrotliEncoderParameter
.
Quality
,
(
uint
)
quality
)
)
if
(
Interop
.
Brotli
.
BrotliEncoderSetParameter
(
_state
,
BrotliEncoderParameter
.
Quality
,
(
uint
)
quality
)
==
Interop
.
BOOL
.
FALSE
)
{
throw
new
InvalidOperationException
(
SR
.
Format
(
SR
.
BrotliEncoder_InvalidSetParameter
,
"Quality"
));
}
...
...
@@ -96,7 +96,7 @@ internal void SetWindow(int window)
{
throw
new
ArgumentOutOfRangeException
(
nameof
(
window
),
SR
.
Format
(
SR
.
BrotliEncoder_Window
,
window
,
BrotliUtils
.
WindowBits_Min
,
BrotliUtils
.
WindowBits_Max
));
}
if
(
!
Interop
.
Brotli
.
BrotliEncoderSetParameter
(
_state
,
BrotliEncoderParameter
.
LGWin
,
(
uint
)
window
)
)
if
(
Interop
.
Brotli
.
BrotliEncoderSetParameter
(
_state
,
BrotliEncoderParameter
.
LGWin
,
(
uint
)
window
)
==
Interop
.
BOOL
.
FALSE
)
{
throw
new
InvalidOperationException
(
SR
.
Format
(
SR
.
BrotliEncoder_InvalidSetParameter
,
"Window"
));
}
...
...
@@ -161,7 +161,7 @@ internal OperationStatus Compress(ReadOnlySpan<byte> source, Span<byte> destinat
fixed
(
byte
*
inBytes
=
&
MemoryMarshal
.
GetReference
(
source
))
fixed
(
byte
*
outBytes
=
&
MemoryMarshal
.
GetReference
(
destination
))
{
if
(
!
Interop
.
Brotli
.
BrotliEncoderCompressStream
(
_state
,
operation
,
ref
availableInput
,
&
inBytes
,
ref
availableOutput
,
&
outBytes
,
out
_
)
)
if
(
Interop
.
Brotli
.
BrotliEncoderCompressStream
(
_state
,
operation
,
ref
availableInput
,
&
inBytes
,
ref
availableOutput
,
&
outBytes
,
out
_
)
==
Interop
.
BOOL
.
FALSE
)
{
return
OperationStatus
.
InvalidData
;
}
...
...
@@ -173,7 +173,7 @@ internal OperationStatus Compress(ReadOnlySpan<byte> source, Span<byte> destinat
bytesWritten
+=
destination
.
Length
-
(
int
)
availableOutput
;
// no bytes written, no remaining input to give to the encoder, and no output in need of retrieving means we are Done
if
((
int
)
availableOutput
==
destination
.
Length
&&
!
Interop
.
Brotli
.
BrotliEncoderHasMoreOutput
(
_state
)
&&
availableInput
==
0
)
if
((
int
)
availableOutput
==
destination
.
Length
&&
Interop
.
Brotli
.
BrotliEncoderHasMoreOutput
(
_state
)
==
Interop
.
BOOL
.
FALSE
&&
availableInput
==
0
)
{
return
OperationStatus
.
Done
;
}
...
...
@@ -218,7 +218,7 @@ public static bool TryCompress(ReadOnlySpan<byte> source, Span<byte> destination
fixed
(
byte
*
outBytes
=
&
MemoryMarshal
.
GetReference
(
destination
))
{
nuint
availableOutput
=
(
nuint
)
destination
.
Length
;
bool
success
=
Interop
.
Brotli
.
BrotliEncoderCompress
(
quality
,
window
,
/*BrotliEncoderMode*/
0
,
(
nuint
)
source
.
Length
,
inBytes
,
ref
availableOutput
,
outBytes
)
;
bool
success
=
Interop
.
Brotli
.
BrotliEncoderCompress
(
quality
,
window
,
/*BrotliEncoderMode*/
0
,
(
nuint
)
source
.
Length
,
inBytes
,
&
availableOutput
,
outBytes
)
!=
Interop
.
BOOL
.
FALSE
;
Debug
.
Assert
(
success
?
availableOutput
<=
(
nuint
)
destination
.
Length
:
availableOutput
==
0
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录