forked from forgejo/forgejo
update: macaron cores,gzip,session (#10522)
Co-authored-by: zeripath <art27@cantab.net>
This commit is contained in:
parent
694f44660f
commit
8d2059a201
47 changed files with 2154 additions and 349 deletions
46
vendor/github.com/klauspost/compress/flate/token.go
generated
vendored
46
vendor/github.com/klauspost/compress/flate/token.go
generated
vendored
|
@ -184,9 +184,7 @@ func (t *tokens) indexTokens(in []token) {
|
|||
t.Reset()
|
||||
for _, tok := range in {
|
||||
if tok < matchType {
|
||||
t.tokens[t.n] = tok
|
||||
t.litHist[tok]++
|
||||
t.n++
|
||||
t.AddLiteral(tok.literal())
|
||||
continue
|
||||
}
|
||||
t.AddMatch(uint32(tok.length()), tok.offset())
|
||||
|
@ -211,50 +209,60 @@ func (t *tokens) AddLiteral(lit byte) {
|
|||
t.nLits++
|
||||
}
|
||||
|
||||
// from https://stackoverflow.com/a/28730362
|
||||
func mFastLog2(val float32) float32 {
|
||||
ux := int32(math.Float32bits(val))
|
||||
log2 := (float32)(((ux >> 23) & 255) - 128)
|
||||
ux &= -0x7f800001
|
||||
ux += 127 << 23
|
||||
uval := math.Float32frombits(uint32(ux))
|
||||
log2 += ((-0.34484843)*uval+2.02466578)*uval - 0.67487759
|
||||
return log2
|
||||
}
|
||||
|
||||
// EstimatedBits will return an minimum size estimated by an *optimal*
|
||||
// compression of the block.
|
||||
// The size of the block
|
||||
func (t *tokens) EstimatedBits() int {
|
||||
shannon := float64(0)
|
||||
shannon := float32(0)
|
||||
bits := int(0)
|
||||
nMatches := 0
|
||||
if t.nLits > 0 {
|
||||
invTotal := 1.0 / float64(t.nLits)
|
||||
invTotal := 1.0 / float32(t.nLits)
|
||||
for _, v := range t.litHist[:] {
|
||||
if v > 0 {
|
||||
n := float64(v)
|
||||
shannon += math.Ceil(-math.Log2(n*invTotal) * n)
|
||||
n := float32(v)
|
||||
shannon += -mFastLog2(n*invTotal) * n
|
||||
}
|
||||
}
|
||||
// Just add 15 for EOB
|
||||
shannon += 15
|
||||
for _, v := range t.extraHist[1 : literalCount-256] {
|
||||
for i, v := range t.extraHist[1 : literalCount-256] {
|
||||
if v > 0 {
|
||||
n := float64(v)
|
||||
shannon += math.Ceil(-math.Log2(n*invTotal) * n)
|
||||
bits += int(lengthExtraBits[v&31]) * int(v)
|
||||
n := float32(v)
|
||||
shannon += -mFastLog2(n*invTotal) * n
|
||||
bits += int(lengthExtraBits[i&31]) * int(v)
|
||||
nMatches += int(v)
|
||||
}
|
||||
}
|
||||
}
|
||||
if nMatches > 0 {
|
||||
invTotal := 1.0 / float64(nMatches)
|
||||
for _, v := range t.offHist[:offsetCodeCount] {
|
||||
invTotal := 1.0 / float32(nMatches)
|
||||
for i, v := range t.offHist[:offsetCodeCount] {
|
||||
if v > 0 {
|
||||
n := float64(v)
|
||||
shannon += math.Ceil(-math.Log2(n*invTotal) * n)
|
||||
bits += int(offsetExtraBits[v&31]) * int(n)
|
||||
n := float32(v)
|
||||
shannon += -mFastLog2(n*invTotal) * n
|
||||
bits += int(offsetExtraBits[i&31]) * int(v)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return int(shannon) + bits
|
||||
}
|
||||
|
||||
// AddMatch adds a match to the tokens.
|
||||
// This function is very sensitive to inlining and right on the border.
|
||||
func (t *tokens) AddMatch(xlength uint32, xoffset uint32) {
|
||||
if debugDecode {
|
||||
if debugDeflate {
|
||||
if xlength >= maxMatchLength+baseMatchLength {
|
||||
panic(fmt.Errorf("invalid length: %v", xlength))
|
||||
}
|
||||
|
@ -273,7 +281,7 @@ func (t *tokens) AddMatch(xlength uint32, xoffset uint32) {
|
|||
// AddMatchLong adds a match to the tokens, potentially longer than max match length.
|
||||
// Length should NOT have the base subtracted, only offset should.
|
||||
func (t *tokens) AddMatchLong(xlength int32, xoffset uint32) {
|
||||
if debugDecode {
|
||||
if debugDeflate {
|
||||
if xoffset >= maxMatchOffset+baseMatchOffset {
|
||||
panic(fmt.Errorf("invalid offset: %v", xoffset))
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue