mirror of
https://bitbucket.org/s_l_teichmann/mtsatellite
synced 2025-01-11 09:20:17 +01:00
Reset zlib reader instead of re-opening it before reading meta data from block. Speeds up decoding of blocks significantly. Using a sync.Pool will seed it up even more.
This commit is contained in:
parent
076ca9fad6
commit
ab1a86384b
@ -86,12 +86,12 @@ func NewDecodedBlock(data []byte, colors *Colors) (db *DecodedBlock, err error)
|
|||||||
if zr, err = zlib.NewReader(&buf); err != nil {
|
if zr, err = zlib.NewReader(&buf); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
defer zr.Close()
|
||||||
|
|
||||||
mapContent := make([]byte, uncompressedLen)
|
mapContent := make([]byte, uncompressedLen)
|
||||||
|
|
||||||
var k int
|
var k int
|
||||||
k, err = io.ReadFull(zr, mapContent)
|
k, err = io.ReadFull(zr, mapContent)
|
||||||
zr.Close()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -105,14 +105,12 @@ func NewDecodedBlock(data []byte, colors *Colors) (db *DecodedBlock, err error)
|
|||||||
buf.Pos = 0
|
buf.Pos = 0
|
||||||
buf.Data = data[offset:]
|
buf.Data = data[offset:]
|
||||||
|
|
||||||
if zr, err = zlib.NewReader(&buf); err != nil {
|
if err = zr.(zlib.Resetter).Reset(&buf, nil); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Discard the meta data.
|
// Discard the meta data.
|
||||||
_, err = io.Copy(ioutil.Discard, zr)
|
if _, err = io.Copy(ioutil.Discard, zr); err != nil {
|
||||||
zr.Close()
|
|
||||||
if err != nil {
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user