mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-18 00:32:11 +01:00
name old speed new speed delta wuffs_bzip2_decode_10k/clang11 58.5MB/s ± 0% 59.9MB/s ± 0% +2.50% (p=0.008 n=5+5) wuffs_bzip2_decode_100k/clang11 45.7MB/s ± 0% 50.5MB/s ± 0% +10.66% (p=0.008 n=5+5) wuffs_bzip2_decode_10k/gcc10 56.2MB/s ± 0% 61.9MB/s ± 0% +10.01% (p=0.008 n=5+5) wuffs_bzip2_decode_100k/gcc10 46.5MB/s ± 0% 50.4MB/s ± 0% +8.41% (p=0.016 n=4+5) wuffs_deflate_decode_1k_full_init/clang11 195MB/s ± 0% 191MB/s ± 0% -1.71% (p=0.008 n=5+5) wuffs_deflate_decode_1k_part_init/clang11 224MB/s ± 0% 225MB/s ± 0% +0.87% (p=0.008 n=5+5) wuffs_deflate_decode_10k_full_init/clang11 421MB/s ± 0% 401MB/s ± 0% -4.59% (p=0.008 n=5+5) wuffs_deflate_decode_10k_part_init/clang11 432MB/s ± 0% 413MB/s ± 0% -4.49% (p=0.008 n=5+5) wuffs_deflate_decode_100k_just_one_read/clang11 542MB/s ± 0% 518MB/s ± 0% -4.43% (p=0.008 n=5+5) wuffs_deflate_decode_100k_many_big_reads/clang11 338MB/s ± 0% 325MB/s ± 0% -3.81% (p=0.008 n=5+5) wuffs_deflate_decode_1k_full_init/gcc10 181MB/s ± 0% 185MB/s ± 0% +1.76% (p=0.008 n=5+5) wuffs_deflate_decode_1k_part_init/gcc10 209MB/s ± 0% 212MB/s ± 0% +1.79% (p=0.008 n=5+5) wuffs_deflate_decode_10k_full_init/gcc10 410MB/s ± 0% 407MB/s ± 0% -0.93% (p=0.008 n=5+5) wuffs_deflate_decode_10k_part_init/gcc10 421MB/s ± 0% 418MB/s ± 0% -0.87% (p=0.008 n=5+5) wuffs_deflate_decode_100k_just_one_read/gcc10 533MB/s ± 0% 533MB/s ± 0% ~ (p=0.548 n=5+5) wuffs_deflate_decode_100k_many_big_reads/gcc10 336MB/s ± 0% 334MB/s ± 1% -0.67% (p=0.008 n=5+5) wuffs_gzip_decode_10k/clang11 401MB/s ± 0% 398MB/s ± 0% -0.77% (p=0.008 n=5+5) wuffs_gzip_decode_100k/clang11 505MB/s ± 0% 503MB/s ± 0% -0.46% (p=0.008 n=5+5) wuffs_gzip_decode_10k/gcc10 403MB/s ± 0% 410MB/s ± 0% +1.90% (p=0.008 n=5+5) wuffs_gzip_decode_100k/gcc10 522MB/s ± 0% 523MB/s ± 0% +0.10% (p=0.032 n=5+5) wuffs_zlib_decode_10k/clang11 418MB/s ± 0% 417MB/s ± 1% ~ (p=0.310 n=5+5) wuffs_zlib_decode_100k/clang11 530MB/s ± 0% 529MB/s ± 0% ~ (p=0.421 n=5+5) wuffs_zlib_decode_10k/gcc10 428MB/s ± 0% 434MB/s ± 0% +1.50% (p=0.008 n=5+5) wuffs_zlib_decode_100k/gcc10 551MB/s ± 0% 551MB/s ± 0% ~ (p=0.690 n=5+5) Fixes #96
148 lines
3.9 KiB
Plaintext
148 lines
3.9 KiB
Plaintext
// Copyright 2018 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/crc32"
|
|
use "std/deflate"
|
|
|
|
pub status "#bad checksum"
|
|
pub status "#bad compression method"
|
|
pub status "#bad encoding flags"
|
|
pub status "#bad header"
|
|
pub status "#truncated input"
|
|
|
|
// 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? implements base.io_transformer(
|
|
ignore_checksum : base.bool,
|
|
checksum : crc32.ieee_hasher,
|
|
|
|
flate : deflate.decoder,
|
|
|
|
util : base.utility,
|
|
)
|
|
|
|
pub func decoder.set_quirk_enabled!(quirk: base.u32, enabled: base.bool) {
|
|
if args.quirk == base.QUIRK_IGNORE_CHECKSUM {
|
|
this.ignore_checksum = args.enabled
|
|
}
|
|
}
|
|
|
|
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.transform_io?(dst: base.io_writer, src: base.io_reader, workbuf: slice base.u8) {
|
|
var status : base.status
|
|
|
|
while true {
|
|
status =? this.do_transform_io?(dst: args.dst, src: args.src, workbuf: args.workbuf)
|
|
if (status == base."$short read") and args.src.is_closed() {
|
|
return "#truncated input"
|
|
}
|
|
yield? status
|
|
} endwhile
|
|
}
|
|
|
|
pri func decoder.do_transform_io?(dst: base.io_writer, src: base.io_reader, workbuf: slice base.u8) {
|
|
var c : base.u8
|
|
var flags : base.u8
|
|
var xlen : base.u16
|
|
var mark : base.u64
|
|
var checksum_got : base.u32
|
|
var decoded_length_got : base.u32
|
|
var status : base.status
|
|
var checksum_want : base.u32
|
|
var decoded_length_want : base.u32
|
|
|
|
// Read the header.
|
|
c = args.src.read_u8?()
|
|
if c <> 0x1F {
|
|
return "#bad header"
|
|
}
|
|
c = args.src.read_u8?()
|
|
if c <> 0x8B {
|
|
return "#bad header"
|
|
}
|
|
c = args.src.read_u8?()
|
|
if c <> 0x08 {
|
|
return "#bad compression method"
|
|
}
|
|
flags = args.src.read_u8?()
|
|
// TODO: API for returning the header's MTIME field.
|
|
args.src.skip_u32?(n: 6)
|
|
|
|
// Handle FEXTRA.
|
|
if (flags & 0x04) <> 0 {
|
|
xlen = args.src.read_u16le?()
|
|
args.src.skip_u32?(n: xlen as base.u32)
|
|
}
|
|
|
|
// Handle FNAME.
|
|
//
|
|
// TODO: API for returning the header's FNAME field. This might require
|
|
// converting ISO 8859-1 to UTF-8. We may also want to cap the UTF-8
|
|
// filename length to NAME_MAX, which is 255.
|
|
if (flags & 0x08) <> 0 {
|
|
while true {
|
|
c = args.src.read_u8?()
|
|
if c == 0 {
|
|
break
|
|
}
|
|
} endwhile
|
|
}
|
|
|
|
// Handle FCOMMENT.
|
|
if (flags & 0x10) <> 0 {
|
|
while true {
|
|
c = args.src.read_u8?()
|
|
if c == 0 {
|
|
break
|
|
}
|
|
} endwhile
|
|
}
|
|
|
|
// Handle FHCRC.
|
|
if (flags & 0x02) <> 0 {
|
|
args.src.skip_u32?(n: 2)
|
|
}
|
|
|
|
// Reserved flags bits must be zero.
|
|
if (flags & 0xE0) <> 0 {
|
|
return "#bad encoding flags"
|
|
}
|
|
|
|
// Decode and checksum the DEFLATE-encoded payload.
|
|
while true {
|
|
mark = args.dst.mark()
|
|
status =? this.flate.transform_io?(dst: args.dst, src: args.src, workbuf: args.workbuf)
|
|
if not this.ignore_checksum {
|
|
checksum_got = this.checksum.update_u32!(x: args.dst.since(mark: mark))
|
|
decoded_length_got ~mod+= (args.dst.count_since(mark: mark) & 0xFFFF_FFFF) as base.u32
|
|
}
|
|
if status.is_ok() {
|
|
break
|
|
}
|
|
yield? status
|
|
} endwhile
|
|
checksum_want = args.src.read_u32le?()
|
|
decoded_length_want = args.src.read_u32le?()
|
|
if (not this.ignore_checksum) and
|
|
((checksum_got <> checksum_want) or (decoded_length_got <> decoded_length_want)) {
|
|
return "#bad checksum"
|
|
}
|
|
}
|