0.3.7, inflate faster

This commit is contained in:
Ryan Oldenburg 2020-11-20 20:10:53 -06:00
parent 0b67f3fa1e
commit d444fbfa47
3 changed files with 25 additions and 27 deletions

View File

@ -131,12 +131,12 @@ Each file is uncompressed 1000 times:
**https://github.com/guzba/zippy** results:
File | Time
--- | ---:
alice29.txt | 0.7797s
urls.10K | 3.5913s
rfctest3.gold | 0.1774s
alice29.txt | 0.7169s
urls.10K | 3.3344s
rfctest3.gold | 0.1618s
randtest3.gold | 0.0373s
paper-100k.pdf | 0.6453s
geo.protodata | 0.2516s
geo.protodata | 0.2298s
https://github.com/nim-lang/zip results: (Requires zlib1.dll)
File | Time

View File

@ -123,29 +123,28 @@ func decodeSymbol(b: var BitStream, h: Huffman): uint16 {.inline.} =
var
bits = b.data[b.bytePos].uint16 shr b.bitPos
numBits = 8 - b.bitPos
bytePos = b.bytePos + 1
# Fill bits up since we know codes must be between 1 and 15 bits long
if b.bytePos + 1 < b.data.len:
bits = bits or (b.data[b.bytePos + 1].uint16 shl numBits)
numBits += 8
if b.bytePos + 2 < b.data.len:
bits = bits or (b.data[b.bytePos + 2].uint16 shl numBits)
numBits = 15
var
chunk = h.chunks[bits and (huffmanNumChunks - 1)]
n = (chunk and huffmanCountMask).int
while true:
if numBits < n:
if bytePos >= b.data.len:
failEndOfBuffer()
bits = bits or (b.data[bytePos].uint16 shl numBits)
inc bytePos
numBits += 8
chunk = h.chunks[bits and (huffmanNumChunks - 1)]
n = (chunk and huffmanCountMask).int
if n > huffmanChunkBits:
chunk = h.links[
chunk shr huffmanValueShift][(bits shr huffmanChunkBits) and h.linkMask
]
n = (chunk and huffmanCountMask).int
if n <= numBits:
if n == 0:
failUncompress()
inc(b.bytePos, (n + b.bitPos) shr 3)
b.bitPos = (n + b.bitPos) and 7
return (chunk shr huffmanValueShift).uint16
if n > huffmanChunkBits:
chunk = h.links[
chunk shr huffmanValueShift][(bits shr huffmanChunkBits) and h.linkMask
]
n = (chunk and huffmanCountMask).int
if n == 0:
failUncompress()
inc(b.bytePos, (n + b.bitPos) shr 3)
b.bitPos = (n + b.bitPos) and 7
return (chunk shr huffmanValueShift).uint16
func inflateBlock(b: var BitStream, dst: var seq[uint8], fixedCodes: bool) =
var literalHuffman, distanceHuffman: Huffman

View File

@ -1,5 +1,4 @@
packageName = "zippy"
version = "0.3.6"
version = "0.3.7"
author = "Ryan Oldenburg"
description = "Pure Nim implementation of deflate, zlib, gzip and zip."
license = "MIT"