Minor getfield opt

This commit is contained in:
tidwall 2019-02-17 13:32:35 -07:00
parent 30d31d0926
commit c69f97d8d6
1 changed files with 11 additions and 26 deletions

View File

@ -1,7 +1,6 @@
package item package item
import ( import (
"fmt"
"unsafe" "unsafe"
"github.com/h2so5/half" "github.com/h2so5/half"
@ -75,7 +74,8 @@ func appendPacked(dst []byte, f64 float64) []byte {
func skipPacked(data []byte, count int) (out []byte, read int) { func skipPacked(data []byte, count int) (out []byte, read int) {
var i int var i int
for i < len(data) { loop: // force inline
if i < len(data) {
if read >= count { if read >= count {
return data[i:], read return data[i:], read
} }
@ -90,6 +90,8 @@ func skipPacked(data []byte, count int) (out []byte, read int) {
i += 9 i += 9
} }
read++ read++
goto loop
} }
return nil, read return nil, read
} }
@ -153,18 +155,6 @@ func (item *Item) packedGenerateFieldBytes(values []float64) []byte {
} }
func (item *Item) packedSetField(index int, value float64) (updated bool) { func (item *Item) packedSetField(index int, value float64) (updated bool) {
if false {
func() {
data := item.fieldsBytes()
fmt.Printf("%v >> [%x]", value, data)
defer func() {
data := item.fieldsBytes()
fmt.Printf(" >> [%x]\n", data)
}()
}()
}
/////////////////////////////////////////////////////////////////
// original field bytes // original field bytes
headBytes := item.fieldsBytes() headBytes := item.fieldsBytes()
@ -269,16 +259,11 @@ func (item *Item) packedForEachField(count int, iter func(value float64) bool) {
} }
func (item *Item) packedGetField(index int) float64 { func (item *Item) packedGetField(index int) float64 {
data := item.fieldsBytes()
var idx int data, _ = skipPacked(data, index)
var fvalue float64 if len(data) == 0 {
item.packedForEachField(-1, func(value float64) bool { return 0
if idx == index { }
fvalue = value _, value := readPacked(data)
return false return value
}
idx++
return true
})
return fvalue
} }