Simplifications when decoding blocks from database to save some memory allocations.

This commit is contained in:
Sascha L. Teichmann 2015-06-21 22:47:06 +02:00
parent 5c239a7b60
commit 2d00eb9567
2 changed files with 11 additions and 14 deletions

View File

@ -45,10 +45,9 @@ func main() {
flag.Parse()
var err error
if !skipBaseLevel {
address := fmt.Sprintf("%s:%d", host, port)
if err = createBaseLevel(
if err := createBaseLevel(
address,
xMin, zMin, xMax, zMax,
transparent,
@ -59,7 +58,7 @@ func main() {
}
}
if !skipPyramid {
if err = createPyramid(outDir, numWorkers); err != nil {
if err := createPyramid(outDir, numWorkers); err != nil {
log.Fatalf("Creating pyramid tiles failed: %s", err)
}
}

View File

@ -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)