mirror of
https://bitbucket.org/s_l_teichmann/mtsatellite
synced 2024-12-24 09:10:17 +01:00
Simplifications when decoding blocks from database to save some memory allocations.
This commit is contained in:
parent
5c239a7b60
commit
2d00eb9567
@ -45,10 +45,9 @@ func main() {
|
|||||||
|
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
var err error
|
|
||||||
if !skipBaseLevel {
|
if !skipBaseLevel {
|
||||||
address := fmt.Sprintf("%s:%d", host, port)
|
address := fmt.Sprintf("%s:%d", host, port)
|
||||||
if err = createBaseLevel(
|
if err := createBaseLevel(
|
||||||
address,
|
address,
|
||||||
xMin, zMin, xMax, zMax,
|
xMin, zMin, xMax, zMax,
|
||||||
transparent,
|
transparent,
|
||||||
@ -59,7 +58,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !skipPyramid {
|
if !skipPyramid {
|
||||||
if err = createPyramid(outDir, numWorkers); err != nil {
|
if err := createPyramid(outDir, numWorkers); err != nil {
|
||||||
log.Fatalf("Creating pyramid tiles failed: %s", err)
|
log.Fatalf("Creating pyramid tiles failed: %s", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -77,29 +77,31 @@ func NewDecodedBlock(data []byte, colors *Colors) (db *DecodedBlock, err error)
|
|||||||
offset = 4
|
offset = 4
|
||||||
}
|
}
|
||||||
|
|
||||||
buf := NewposBuf(data[offset:])
|
buf := posBuf{Data: data[offset:]}
|
||||||
var zr io.ReadCloser
|
var zr io.ReadCloser
|
||||||
if zr, err = zlib.NewReader(buf); err != nil {
|
if zr, err = zlib.NewReader(&buf); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
var mapContent []byte
|
mapContent := make([]byte, uncompressedLen)
|
||||||
mapContent, err = ioutil.ReadAll(zr)
|
|
||||||
|
var k int
|
||||||
|
k, err = io.ReadFull(zr, mapContent)
|
||||||
zr.Close()
|
zr.Close()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if uncompressedLen != len(mapContent) {
|
if k != uncompressedLen {
|
||||||
err = ErrMapContentSizeMismatch
|
err = ErrMapContentSizeMismatch
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
offset += buf.Pos
|
offset += buf.Pos + 4
|
||||||
buf.Pos = 0
|
buf.Pos = 0
|
||||||
buf.Data = data[offset:]
|
buf.Data = data[offset:]
|
||||||
|
|
||||||
if zr, err = zlib.NewReader(buf); err != nil {
|
if zr, err = zlib.NewReader(&buf); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -204,10 +206,6 @@ func (db *DecodedBlock) Content(x, y, z int) (content int32, found bool) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewposBuf(data []byte) *posBuf {
|
|
||||||
return &posBuf{Data: data}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (pb *posBuf) Read(p []byte) (int, error) {
|
func (pb *posBuf) Read(p []byte) (int, error) {
|
||||||
pl := len(p)
|
pl := len(p)
|
||||||
ml := len(pb.Data)
|
ml := len(pb.Data)
|
||||||
|
Loading…
Reference in New Issue
Block a user