From 3ee07c92d1a14f3324bfa2f24aed2c8404feb189 Mon Sep 17 00:00:00 2001 From: prunedtree Date: Mon, 5 Oct 2009 20:12:59 -0700 Subject: [PATCH] static inflate --- basis/compression/inflate/inflate.factor | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/basis/compression/inflate/inflate.factor b/basis/compression/inflate/inflate.factor index ff38f94c68..e56b2c7a1c 100644 --- a/basis/compression/inflate/inflate.factor +++ b/basis/compression/inflate/inflate.factor @@ -67,7 +67,15 @@ CONSTANT: clen-shuffle { 16 17 18 0 8 7 9 6 10 5 11 4 12 3 13 2 14 1 15 } { } [ dup array? [ dup first 16 = ] [ f ] if [ [ unclip-last ] [ second 1 + swap append ] bi* ] [ suffix ] if ] reduce [ dup array? [ second 0 ] [ 1array ] if ] map concat nip swap cut 2array [ [ length>> [0,b) ] [ ] bi get-table ] map ; - + +: static-huffman-tables ( -- tables ) + 0 143 [a,b] [ 8 ] replicate + 144 255 [a,b] [ 9 ] replicate append + 256 279 [a,b] [ 7 ] replicate append + 280 287 [a,b] [ 8 ] replicate append + 0 31 [a,b] [ 5 ] replicate + 2array [ [ length>> [0,b) ] [ ] bi get-table ] map ; + CONSTANT: length-table { 3 4 5 6 7 8 9 10 @@ -103,9 +111,8 @@ CONSTANT: dist-table ] each bytes ; -:: inflate-dynamic ( bitstream -- bytes ) - bitstream decode-huffman-tables - bitstream '[ _ swap ] map :> tables +:: inflate-huffman ( bitstream tables -- bytes ) + tables bitstream '[ _ swap ] map :> tables [ tables first read1-huff2 dup 256 > @@ -161,7 +168,11 @@ CONSTANT: dist-table bitstream bytes>> len 8 * bitstream bs:seek ; -: inflate-static ( bitstream -- bytes ) zlib-unimplemented ; +: inflate-dynamic ( bitstream -- bytes ) + dup decode-huffman-tables inflate-huffman ; + +: inflate-static ( bitstream -- bytes ) + static-huffman-tables inflate-huffman ; :: inflate-loop ( bitstream -- bytes ) [ 1 bitstream bs:read 0 = ]