mirror of
https://bitbucket.org/s_l_teichmann/mtsatellite
synced 2025-06-28 14:16:24 +02:00
Simplifications when decoding blocks from database to save some memory allocations.
This commit is contained in:
@ -77,29 +77,31 @@ func NewDecodedBlock(data []byte, colors *Colors) (db *DecodedBlock, err error)
|
||||
offset = 4
|
||||
}
|
||||
|
||||
buf := NewposBuf(data[offset:])
|
||||
buf := posBuf{Data: data[offset:]}
|
||||
var zr io.ReadCloser
|
||||
if zr, err = zlib.NewReader(buf); err != nil {
|
||||
if zr, err = zlib.NewReader(&buf); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
var mapContent []byte
|
||||
mapContent, err = ioutil.ReadAll(zr)
|
||||
mapContent := make([]byte, uncompressedLen)
|
||||
|
||||
var k int
|
||||
k, err = io.ReadFull(zr, mapContent)
|
||||
zr.Close()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if uncompressedLen != len(mapContent) {
|
||||
if k != uncompressedLen {
|
||||
err = ErrMapContentSizeMismatch
|
||||
return
|
||||
}
|
||||
|
||||
offset += buf.Pos
|
||||
offset += buf.Pos + 4
|
||||
buf.Pos = 0
|
||||
buf.Data = data[offset:]
|
||||
|
||||
if zr, err = zlib.NewReader(buf); err != nil {
|
||||
if zr, err = zlib.NewReader(&buf); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
@ -204,10 +206,6 @@ func (db *DecodedBlock) Content(x, y, z int) (content int32, found bool) {
|
||||
return
|
||||
}
|
||||
|
||||
func NewposBuf(data []byte) *posBuf {
|
||||
return &posBuf{Data: data}
|
||||
}
|
||||
|
||||
func (pb *posBuf) Read(p []byte) (int, error) {
|
||||
pl := len(p)
|
||||
ml := len(pb.Data)
|
||||
|
Reference in New Issue
Block a user