Source File
deflatefast.go
Belonging Package
compress/flate
package flate
import
bufferReset = math.MaxInt32 - maxStoreBlockSize*2
)
func ( []byte, int32) uint32 {
= [ : +4 : len()] // Help the compiler eliminate bounds checks on the next line.
return uint32([0]) | uint32([1])<<8 | uint32([2])<<16 | uint32([3])<<24
}
func ( []byte, int32) uint64 {
= [ : +8 : len()] // Help the compiler eliminate bounds checks on the next line.
return uint64([0]) | uint64([1])<<8 | uint64([2])<<16 | uint64([3])<<24 |
uint64([4])<<32 | uint64([5])<<40 | uint64([6])<<48 | uint64([7])<<56
}
func ( uint32) uint32 {
return ( * 0x1e35a7bd) >> tableShift
}
const (
inputMargin = 16 - 1
minNonLiteralBlockSize = 1 + 1 + inputMargin
)
type tableEntry struct {
val uint32 // Value at destination
offset int32
}
type deflateFast struct {
table [tableSize]tableEntry
prev []byte // Previous block, zero length if unknown.
cur int32 // Current match offset.
}
func () *deflateFast {
return &deflateFast{cur: maxStoreBlockSize, prev: make([]byte, 0, maxStoreBlockSize)}
}
if .cur >= bufferReset {
.shiftOffsets()
}
if len() < minNonLiteralBlockSize {
.cur += maxStoreBlockSize
.prev = .prev[:0]
return emitLiteral(, )
}
:= int32(len() - inputMargin)
=
continue
}
break
}
= emitLiteral(, [:])
= append(, matchToken(uint32(+4-baseMatchLength), uint32(--baseMatchOffset)))
+=
=
if >= {
goto
}
:= load64(, -1)
:= hash(uint32())
.table[&tableMask] = tableEntry{offset: .cur + - 1, val: uint32()}
>>= 8
:= hash(uint32())
= .table[&tableMask]
.table[&tableMask] = tableEntry{offset: .cur + , val: uint32()}
:= - (.offset - .cur)
if > maxMatchOffset || uint32() != .val {
= uint32( >> 8)
= hash()
++
break
}
}
}
:
if int() < len() {
= emitLiteral(, [:])
}
.cur += int32(len())
.prev = .prev[:len()]
copy(.prev, )
return
}
func ( []token, []byte) []token {
for , := range {
= append(, literalToken(uint32()))
}
return
}
func ( *deflateFast) (, int32, []byte) int32 {
:= int() + maxMatchLength - 4
if > len() {
= len()
}
if >= 0 {
:= [:]
:= [:]
func ( *deflateFast) () {
.cur += maxMatchOffset
if .cur >= bufferReset {
.shiftOffsets()
}
}
func ( *deflateFast) () {
for := range .table[:] {
.table[] = tableEntry{}
}
.cur = maxMatchOffset + 1
return
}
for := range .table[:] {
:= .table[].offset - .cur + maxMatchOffset + 1
= 0
}
.table[].offset =
}
.cur = maxMatchOffset + 1
![]() |
The pages are generated with Golds v0.3.2-preview. (GOOS=darwin GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds. |