Rename std/bzip2 decode_block_* functions

This commit is contained in:
Nigel Tao committed 2022-05-24 11:24:57 +10:00
1 parent fc0c5e465b
commit ae1e075401
4 files changed
+86 -86

No files matched your search

+16 -16
View File
@@ -36,12 +36,12 @@ pub struct decoder? implements base.io_transformer(
// Block size is measured prior to the RLE1 step.
max_incl_block_size : base.u32[..= 900000],
block_size : base.u32[..= 900000],
decode_block_finished : base.bool,
decode_block_which : base.u8[..= 5],
decode_block_ticks : base.u32[..= 50],
decode_block_section : base.u32,
decode_block_run_shift : base.u32[..= 23],
block_size : base.u32[..= 900000],
decode_huffman_finished : base.bool,
decode_huffman_which : base.u8[..= 5],
decode_huffman_ticks : base.u32[..= 50],
decode_huffman_section : base.u32,
decode_huffman_run_shift : base.u32[..= 23],
final_checksum_have : base.u32,
block_checksum_want : base.u32,
@@ -158,19 +158,19 @@ pub func decoder.transform_io?(dst: base.io_writer, src: base.io_reader, workbuf
this.prepare_block?(src: args.src)
this.block_size = 0
this.decode_block_finished = false
this.decode_block_which = CLAMP_TO_5[this.huffman_selectors[0] & 7]
this.decode_block_ticks = 50
this.decode_block_section = 0
this.decode_block_run_shift = 0
while not this.decode_block_finished {
status = this.decode_block_fast!(src: args.src)
this.decode_huffman_finished = false
this.decode_huffman_which = CLAMP_TO_5[this.huffman_selectors[0] & 7]
this.decode_huffman_ticks = 50
this.decode_huffman_section = 0
this.decode_huffman_run_shift = 0
while not this.decode_huffman_finished {
status = this.decode_huffman_fast!(src: args.src)
if status.is_error() {
return status
} else if this.decode_block_finished {
} else if this.decode_huffman_finished {
break
}
this.decode_block_slow?(src: args.src)
this.decode_huffman_slow?(src: args.src)
} endwhile
this.invert_bwt!()
@@ -668,7 +668,7 @@ pri func decoder.build_huffman_table!(which: base.u32[..= 5]) {
// invert_bwt performs "two passes over the data, and one pass over the
// alphabet", per the BWT technical report, except that the first data pass
// (accumulating this.letter_counts) is integrated into the decode_block_etc
// (accumulating this.letter_counts) is integrated into the decode_huffman_etc
// methods.
pri func decoder.invert_bwt!() {
var i : base.u32
+10 -10
View File
@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
pri func decoder.decode_block_fast!(src: base.io_reader) base.status {
pri func decoder.decode_huffman_fast!(src: base.io_reader) base.status {
var bits : base.u32
var n_bits : base.u32[..= 31]
var block_size : base.u32[..= 900000]
@@ -33,10 +33,10 @@ pri func decoder.decode_block_fast!(src: base.io_reader) base.status {
bits = this.bits
n_bits = this.n_bits
block_size = this.block_size
which = this.decode_block_which
ticks = this.decode_block_ticks
section = this.decode_block_section
run_shift = this.decode_block_run_shift
which = this.decode_huffman_which
ticks = this.decode_huffman_ticks
section = this.decode_huffman_section
run_shift = this.decode_huffman_run_shift
// Apply the Huffman trees.
while.outer args.src.length() >= 4 {
@@ -83,7 +83,7 @@ pri func decoder.decode_block_fast!(src: base.io_reader) base.status {
run_shift = 0
continue.outer
} else if child > 1281 { // EOB symbol.
this.decode_block_finished = true
this.decode_huffman_finished = true
break.outer
}
@@ -115,10 +115,10 @@ pri func decoder.decode_block_fast!(src: base.io_reader) base.status {
this.bits = bits
this.n_bits = n_bits
this.block_size = block_size
this.decode_block_which = which
this.decode_block_ticks = ticks
this.decode_block_section = section
this.decode_block_run_shift = run_shift
this.decode_huffman_which = which
this.decode_huffman_ticks = ticks
this.decode_huffman_section = section
this.decode_huffman_run_shift = run_shift
return ok
}
+12 -12
View File
@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
pri func decoder.decode_block_slow?(src: base.io_reader) {
pri func decoder.decode_huffman_slow?(src: base.io_reader) {
var c : base.u8
var node_index : base.u32[..= 1023]
@@ -26,12 +26,12 @@ pri func decoder.decode_block_slow?(src: base.io_reader) {
// Apply the Huffman trees.
while.outer not coroutine_resumed {
if this.decode_block_ticks > 0 {
this.decode_block_ticks -= 1
if this.decode_huffman_ticks > 0 {
this.decode_huffman_ticks -= 1
} else {
this.decode_block_ticks = 49
this.decode_block_section ~mod+= 1
this.decode_block_which = CLAMP_TO_5[this.huffman_selectors[this.decode_block_section & 32767] & 7]
this.decode_huffman_ticks = 49
this.decode_huffman_section ~mod+= 1
this.decode_huffman_which = CLAMP_TO_5[this.huffman_selectors[this.decode_huffman_section & 32767] & 7]
}
node_index = 0
@@ -42,7 +42,7 @@ pri func decoder.decode_block_slow?(src: base.io_reader) {
this.n_bits = 8
assert this.n_bits > 0
}
child = this.huffman_trees[this.decode_block_which][node_index][this.bits >> 31]
child = this.huffman_trees[this.decode_huffman_which][node_index][this.bits >> 31]
this.bits ~mod<<= 1
this.n_bits -= 1
@@ -65,20 +65,20 @@ pri func decoder.decode_block_slow?(src: base.io_reader) {
}
assert this.block_size < 900000 via "a < b: a < c; c <= b"(c: this.max_incl_block_size)
this.block_size += 1
this.decode_block_run_shift = 0
this.decode_huffman_run_shift = 0
break
} else if child > 1281 { // EOB symbol.
this.decode_block_finished = true
this.decode_huffman_finished = true
break.outer
}
// RUNA or RUNB symbol.
if this.decode_block_run_shift >= 23 {
if this.decode_huffman_run_shift >= 23 {
return "#bad block length"
}
run = ((child - 1279) as base.u32) << this.decode_block_run_shift
this.decode_block_run_shift += 1
run = ((child - 1279) as base.u32) << this.decode_huffman_run_shift
this.decode_huffman_run_shift += 1
i = this.block_size
j = run + this.block_size
if j > this.max_incl_block_size {