std/brotli: add encoder raw (prefix) dictionaries

Mirror BrotliEncoderPrepareDictionary (BROTLI_SHARED_DICTIONARY_RAW),
CreatePreparedDictionary and BrotliEncoderAttachPreparedDictionary as
encoder.add_dictionary, with the prepared hash tables (slot offsets,
heads and items) in the workbuf after the dictionary bytes, and the
compound dictionary search (FindCompoundDictionaryMatch and
LookupCompoundDictionaryMatch) for the hashers whose
CreateBackwardReferences variant enables it, the compound dictionary
gap for static dictionary distances and the compound branch of
ExtendLastCommand.

Extend the encoder parity script with a -dict grid that also checks
round trips through libbrotlidec and the Wuffs decoder.
This commit is contained in:
Claude committed 2026-10-27 04:54:39 +00:00
1 parent b52e608b7c
commit aabdeaf4b0
6 files changed
+2057 -77

No files matched your search

+13 -7
View File
@@ -474,10 +474,11 @@ pri func encoder.update_size_hint!(available_in: base.u64) {
}
}
// Mirrors ExtendLastCommand in encode.c (without a compound dictionary). It
// returns how many bytes it extended the last command by: the caller
// subtracts that from bytes and adds it to wrapped_last_processed_pos.
pri func encoder.extend_last_command!(wb: slice base.u8, bytes: base.u64, wrapped_last_processed_pos: base.u64) base.u64 {
// Mirrors ExtendLastCommand in encode.c (see extend_last_command_compound
// for its compound dictionary branch). It returns how many bytes it extended
// the last command by: the caller subtracts that from bytes and adds it to
// wrapped_last_processed_pos.
pri func encoder.extend_last_command!(wb: slice base.u8, dwb: roslice base.u8, bytes: base.u64, wrapped_last_processed_pos: base.u64) base.u64 {
var last : base.u64
var max_backward_distance : base.u64
var copy_len : base.u32
@@ -506,6 +507,11 @@ pri func encoder.extend_last_command!(wb: slice base.u8, bytes: base.u64, wrappe
n ~mod+= 1
p = (p ~mod+ 1) & 0xFFFF_FFFF
}
} else {
n = this.extend_last_command_compound(wb: args.wb, dwb: args.dwb, bytes: args.bytes,
wrapped_last_processed_pos: args.wrapped_last_processed_pos,
cmd_dist: cmd_dist, max_distance: max_distance, last_copy_len: last_copy_len)
copy_len ~mod+= (n & 0xFFFF_FFFF) as base.u32
}
// The copy length is at most the metablock size, and thus
// expressible.
@@ -857,7 +863,7 @@ pri func encoder.write_meta_block_internal!(wb: slice base.u8, last_flush_pos: b
// Mirrors EncodeData in encode.c, for qualities 2 to 9. On a new metablock,
// it sets the pending output (this.out_etc) to the storage (or tiny_buf).
pri func encoder.encode_data!(wb: slice base.u8, is_last: base.bool, force_flush: base.bool) base.status {
pri func encoder.encode_data!(wb: slice base.u8, dwb: roslice base.u8, is_last: base.bool, force_flush: base.bool) base.status {
var status : base.status
var delta : base.u64
var bytes : base.u64
@@ -916,13 +922,13 @@ pri func encoder.encode_data!(wb: slice base.u8, is_last: base.bool, force_flush
this.hasher_stitch_to_previous_block!(wb: args.wb, num_bytes: bytes, position: wrapped_last_processed_pos)
if (this.num_cmds > 0) and (this.last_insert_len == 0) {
n = this.extend_last_command!(wb: args.wb, bytes: bytes,
n = this.extend_last_command!(wb: args.wb, dwb: args.dwb, bytes: bytes,
wrapped_last_processed_pos: wrapped_last_processed_pos)
bytes ~mod-= n
wrapped_last_processed_pos = (wrapped_last_processed_pos ~mod+ n) & 0xFFFF_FFFF
}
status = this.create_backward_references!(wb: args.wb, num_bytes: bytes, position: wrapped_last_processed_pos)
status = this.create_backward_references!(wb: args.wb, dwb: args.dwb, num_bytes: bytes, position: wrapped_last_processed_pos)
if not status.is_ok() {
return status
}