Commit c7873ff2 authored by Ryan Hitchman's avatar Ryan Hitchman Committed by Russ Cox

compress/flate: shrink decompressor struct for better performance

Helps with issue 2703.

R=dave, minux.ma, rsc
CC=golang-dev
https://golang.org/cl/5536078
parent 85d60a72
...@@ -208,8 +208,8 @@ type decompressor struct { ...@@ -208,8 +208,8 @@ type decompressor struct {
h1, h2 huffmanDecoder h1, h2 huffmanDecoder
// Length arrays used to define Huffman codes. // Length arrays used to define Huffman codes.
bits [maxLit + maxDist]int bits *[maxLit + maxDist]int
codebits [numCodes]int codebits *[numCodes]int
// Output history, buffer. // Output history, buffer.
hist *[maxHist]byte hist *[maxHist]byte
...@@ -692,6 +692,8 @@ func makeReader(r io.Reader) Reader { ...@@ -692,6 +692,8 @@ func makeReader(r io.Reader) Reader {
// finished reading. // finished reading.
func NewReader(r io.Reader) io.ReadCloser { func NewReader(r io.Reader) io.ReadCloser {
var f decompressor var f decompressor
f.bits = new([maxLit + maxDist]int)
f.codebits = new([numCodes]int)
f.r = makeReader(r) f.r = makeReader(r)
f.hist = new([maxHist]byte) f.hist = new([maxHist]byte)
f.step = (*decompressor).nextBlock f.step = (*decompressor).nextBlock
...@@ -707,6 +709,8 @@ func NewReaderDict(r io.Reader, dict []byte) io.ReadCloser { ...@@ -707,6 +709,8 @@ func NewReaderDict(r io.Reader, dict []byte) io.ReadCloser {
var f decompressor var f decompressor
f.r = makeReader(r) f.r = makeReader(r)
f.hist = new([maxHist]byte) f.hist = new([maxHist]byte)
f.bits = new([maxLit + maxDist]int)
f.codebits = new([numCodes]int)
f.step = (*decompressor).nextBlock f.step = (*decompressor).nextBlock
f.setDict(dict) f.setDict(dict)
return &f return &f
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment