mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-17 16:32:11 +01:00
name old speed new speed delta wuffs_deflate_decode_1k_full_init/clang5 149MB/s ± 0% 151MB/s ± 1% +1.46% (p=0.000 n=9+7) wuffs_deflate_decode_1k_part_init/clang5 183MB/s ± 1% 188MB/s ± 2% +2.40% (p=0.000 n=10+10) wuffs_deflate_decode_10k_full_init/clang5 236MB/s ± 0% 242MB/s ± 1% +2.56% (p=0.000 n=10+10) wuffs_deflate_decode_10k_part_init/clang5 243MB/s ± 0% 249MB/s ± 0% +2.36% (p=0.000 n=9+9) wuffs_deflate_decode_100k_just_one_read/clang5 279MB/s ± 0% 288MB/s ± 1% +3.28% (p=0.000 n=9+8) wuffs_deflate_decode_100k_many_big_reads/clang5 232MB/s ± 0% 240MB/s ± 1% +3.76% (p=0.000 n=9+9) wuffs_deflate_decode_1k_full_init/gcc7 152MB/s ± 1% 152MB/s ± 1% ~ (p=0.661 n=10+9) wuffs_deflate_decode_1k_part_init/gcc7 188MB/s ± 0% 187MB/s ± 1% -0.58% (p=0.013 n=10+9) wuffs_deflate_decode_10k_full_init/gcc7 260MB/s ± 0% 260MB/s ± 0% ~ (p=0.393 n=10+10) wuffs_deflate_decode_10k_part_init/gcc7 268MB/s ± 0% 268MB/s ± 0% ~ (p=0.971 n=10+10) wuffs_deflate_decode_100k_just_one_read/gcc7 312MB/s ± 1% 312MB/s ± 0% ~ (p=0.720 n=10+9) wuffs_deflate_decode_100k_many_big_reads/gcc7 247MB/s ± 1% 247MB/s ± 0% -0.26% (p=0.022 n=10+9)
85 lines
2.3 KiB
Plaintext
85 lines
2.3 KiB
Plaintext
// Copyright 2017 The Wuffs Authors.
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// https://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
use "std/adler32"
|
|
use "std/deflate"
|
|
|
|
pub status "#bad checksum"
|
|
pub status "#bad compression method"
|
|
pub status "#bad compression window size"
|
|
pub status "#bad parity check"
|
|
|
|
pri status "#TODO: unsupported preset dictionary"
|
|
|
|
// TODO: reference deflate.decoder_workbuf_len_max_incl_worst_case.
|
|
pub const decoder_workbuf_len_max_incl_worst_case base.u64 = 1
|
|
|
|
pub struct decoder?(
|
|
ignore_checksum base.bool,
|
|
checksum adler32.hasher,
|
|
|
|
flate deflate.decoder,
|
|
|
|
util base.utility,
|
|
)
|
|
|
|
pub func decoder.set_ignore_checksum!(ic base.bool) {
|
|
this.ignore_checksum = args.ic
|
|
}
|
|
|
|
pub func decoder.workbuf_len() base.range_ii_u64 {
|
|
return this.util.make_range_ii_u64(
|
|
min_incl:decoder_workbuf_len_max_incl_worst_case,
|
|
max_incl:decoder_workbuf_len_max_incl_worst_case)
|
|
}
|
|
|
|
pub func decoder.decode_io_writer?(dst base.io_writer, src base.io_reader, workbuf slice base.u8) {
|
|
var x base.u16
|
|
var checksum_got base.u32
|
|
var status base.status
|
|
var checksum_want base.u32
|
|
var mark base.u64
|
|
|
|
x = args.src.read_u16be?()
|
|
if ((x >> 8) & 0x0F) <> 0x08 {
|
|
return "#bad compression method"
|
|
}
|
|
if (x >> 12) > 0x07 {
|
|
return "#bad compression window size"
|
|
}
|
|
if (x & 0x20) <> 0 {
|
|
return "#TODO: unsupported preset dictionary"
|
|
}
|
|
if (x % 31) <> 0 {
|
|
return "#bad parity check"
|
|
}
|
|
|
|
// Decode and checksum the DEFLATE-encoded payload.
|
|
while true {
|
|
mark = args.dst.mark()
|
|
status =? this.flate.decode_io_writer?(dst:args.dst, src:args.src, workbuf:args.workbuf)
|
|
if not this.ignore_checksum {
|
|
checksum_got = this.checksum.update!(x:args.dst.since(mark:mark))
|
|
}
|
|
if status.is_ok() {
|
|
break
|
|
}
|
|
yield? status
|
|
}
|
|
checksum_want = args.src.read_u32be?()
|
|
if (not this.ignore_checksum) and (checksum_got <> checksum_want) {
|
|
return "#bad checksum"
|
|
}
|
|
}
|