faster compress, ~5%
This commit is contained in:
parent
085b916cf4
commit
ebe678443f
|
@ -114,11 +114,11 @@ func uncompress(
|
|||
|
||||
inflate(src[pos ..< ^8], dst)
|
||||
|
||||
let checksum = cast[ptr uint32](src[src.len - 8].unsafeAddr)[]
|
||||
let checksum = read32(src[src.len - 8].unsafeAddr)
|
||||
if checksum != crc32(dst):
|
||||
raise newException(ZippyError, "Checksum verification failed")
|
||||
|
||||
let isize = cast[ptr uint32](src[src.len - 4].unsafeAddr)[]
|
||||
let isize = read32(src[src.len - 4].unsafeAddr)
|
||||
if isize != dst.len.uint32:
|
||||
raise newException(ZippyError, "Size verification failed")
|
||||
of dfZlib:
|
||||
|
|
|
@ -101,6 +101,9 @@ const
|
|||
when defined(release):
|
||||
{.push checks: off.}
|
||||
|
||||
template read32*(p: pointer): uint32 =
|
||||
cast[ptr uint32](p)[]
|
||||
|
||||
func adler32*(data: seq[uint8]): uint32 =
|
||||
## See https://github.com/madler/zlib/blob/master/adler32.c
|
||||
|
||||
|
|
|
@ -284,10 +284,15 @@ func lz77Encode(src: seq[uint8]): (seq[uint16], seq[int], seq[int], int) =
|
|||
prevOffset = offset
|
||||
|
||||
var matchLen: int
|
||||
for i in 0 ..< stop - pos:
|
||||
if src[pos - offset + i] != src[pos + i]:
|
||||
break
|
||||
inc matchLen
|
||||
if (
|
||||
(read32(src[pos - offset].unsafeAddr) xor read32(src[pos].unsafeAddr)
|
||||
) shl 8) == 0:
|
||||
# The first 3 bytes match (the hash of them got us here so usually do)
|
||||
inc(matchLen, 3)
|
||||
for i in 3 ..< stop - pos:
|
||||
if src[pos - offset + i] != src[pos + i]:
|
||||
break
|
||||
inc matchLen
|
||||
|
||||
if matchLen > longestMatchLen:
|
||||
longestMatchLen = matchLen
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import miniz, nimPNG/nimz, std/monotimes, strformat, zip/zlib, zippy
|
||||
import std/monotimes, strformat, zip/zlib, zippy
|
||||
# import miniz, nimPNG/nimz,
|
||||
|
||||
const
|
||||
zs = [
|
||||
|
|
Loading…
Reference in New Issue