authorgravatar for goon.pri.low@gmail.comKendall Condon <goon.pri.low@gmail.com> 2025-11-11 16:14:39-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-11-22 22:11:33-08:00
log8284da2f3d5179d9c3160edd8d167b5169dbe126
tree812136a96efc135c93c5c270e08eae82a1fc109d
parentd6931b0ff5097edbcb855d78056ac9ecd8d075da

flate.Compress: simplify huffman node comparisons

Instead of comparing each field, nodes are now compared as 32-bit values where `freq` is in the most significant bits.

1 files changed, 4 insertions(+), 3 deletions(-)

lib/std/compress/flate/Compress.zig+4-3
......@@ -993,14 +993,15 @@ const huffman = struct {
993993 const max_leafs = 286;
994994 const max_nodes = max_leafs * 2;
995995
996 const Node = struct {
997 freq: u16,
996 const Node = packed struct(u32) {
998997 depth: u16,
998 freq: u16,
999999
10001000 pub const Index = u16;
10011001
1002 /// `freq` is more significant than `depth`
10021003 pub fn smaller(a: Node, b: Node) bool {
1003 return if (a.freq != b.freq) a.freq < b.freq else a.depth < b.depth;
1004 return @as(u32, @bitCast(a)) < @as(u32, @bitCast(b));
10041005 }
10051006 };
10061007