mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-23 08:47:56 +01:00
Have lib/raczlib use lib/cgozlib
As the cmd/ractool comment changes say, this is almost a 2x speed-up for RAC+Zlib decoding on the enwik8 test file, comparable to the cgozlib benchmark numbers: $ go test -test.bench=. github.com/google/wuffs/lib/cgozlib goos: linux goarch: amd64 pkg: github.com/google/wuffs/lib/cgozlib BenchmarkCgo-56 2514 477230 ns/op BenchmarkPure-56 1090 1080853 ns/op
This commit is contained in:
1 parent
5125e51916
commit
fed2073b00
5 files changed
+104
-38
No files matched your search
+12
-20
@@ -54,11 +54,22 @@ func suffix32K(b []byte) []byte {
|
||||
return b
|
||||
}
|
||||
|
||||
type resetReadCloser interface {
|
||||
// Reset is the zlib.Resetter interface's sole method.
|
||||
//
|
||||
// We explicitly spell out the method signature, instead of just saying
|
||||
// "zlib.Resetter". It may be possible for a future version of this package
|
||||
// to not depend on the standard library's "compress/zlib" package at all.
|
||||
Reset(r io.Reader, dict []byte) error
|
||||
|
||||
io.ReadCloser
|
||||
}
|
||||
|
||||
// CodecReader specializes a rac.Reader to decode Zlib-compressed chunks.
|
||||
type CodecReader struct {
|
||||
// cachedZlibReader lets us re-use the memory allocated for a zlib reader,
|
||||
// when decompressing multiple chunks.
|
||||
cachedZlibReader zlib.Resetter
|
||||
cachedZlibReader resetReadCloser
|
||||
|
||||
// These fields contain the most recently used shared dictionary.
|
||||
cachedDictionary []byte
|
||||
@@ -78,25 +89,6 @@ func (r *CodecReader) Clone() rac.CodecReader {
|
||||
return &CodecReader{}
|
||||
}
|
||||
|
||||
// MakeDecompressor implements rac.CodecReader.
|
||||
func (r *CodecReader) MakeDecompressor(
|
||||
compressed io.Reader, rctx rac.ReaderContext) (io.Reader, error) {
|
||||
|
||||
if r.cachedZlibReader != nil {
|
||||
if err := r.cachedZlibReader.Reset(compressed, rctx.Secondary); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return r.cachedZlibReader.(io.Reader), nil
|
||||
}
|
||||
|
||||
zlibReader, err := zlib.NewReaderDict(compressed, rctx.Secondary)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
r.cachedZlibReader = zlibReader.(zlib.Resetter)
|
||||
return zlibReader, nil
|
||||
}
|
||||
|
||||
// MakeReaderContext implements rac.CodecReader.
|
||||
func (r *CodecReader) MakeReaderContext(rs io.ReadSeeker, chunk rac.Chunk) (rac.ReaderContext, error) {
|
||||
// For a description of the RAC+Zlib secondary-data format, see
|
||||
|
||||
Reference in new issue
Block a user