mirror of https://github.com/tidwall/tile38.git
Merge pull request #534 from rshura/optimize-scanwriter
Avoid sorting fields for each written object.
This commit is contained in:
commit
0997f2e82b
|
@ -2,6 +2,7 @@ package collection
|
|||
|
||||
import (
|
||||
"runtime"
|
||||
"sort"
|
||||
|
||||
"github.com/tidwall/btree"
|
||||
"github.com/tidwall/geoindex"
|
||||
|
@ -319,6 +320,7 @@ func (c *Collection) FieldArr() []string {
|
|||
for field, i := range c.fieldMap {
|
||||
arr[i] = field
|
||||
}
|
||||
sort.Strings(arr)
|
||||
return arr
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,6 @@ package server
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
@ -23,22 +22,12 @@ type fvt struct {
|
|||
value float64
|
||||
}
|
||||
|
||||
type byField []fvt
|
||||
|
||||
func (a byField) Len() int {
|
||||
return len(a)
|
||||
}
|
||||
func (a byField) Less(i, j int) bool {
|
||||
return a[i].field < a[j].field
|
||||
}
|
||||
func (a byField) Swap(i, j int) {
|
||||
a[i], a[j] = a[j], a[i]
|
||||
}
|
||||
|
||||
func orderFields(fmap map[string]int, fields []float64) []fvt {
|
||||
func orderFields(fmap map[string]int, farr []string, fields []float64) []fvt {
|
||||
var fv fvt
|
||||
var idx int
|
||||
fvs := make([]fvt, 0, len(fmap))
|
||||
for field, idx := range fmap {
|
||||
for _, field := range farr {
|
||||
idx = fmap[field]
|
||||
if idx < len(fields) {
|
||||
fv.field = field
|
||||
fv.value = fields[idx]
|
||||
|
@ -47,7 +36,6 @@ func orderFields(fmap map[string]int, fields []float64) []fvt {
|
|||
}
|
||||
}
|
||||
}
|
||||
sort.Sort(byField(fvs))
|
||||
return fvs
|
||||
}
|
||||
func (server *Server) cmdBounds(msg *Message) (resp.Value, error) {
|
||||
|
@ -255,7 +243,7 @@ func (server *Server) cmdGet(msg *Message) (resp.Value, error) {
|
|||
return NOMessage, errInvalidNumberOfArguments
|
||||
}
|
||||
if withfields {
|
||||
fvs := orderFields(col.FieldMap(), fields)
|
||||
fvs := orderFields(col.FieldMap(), col.FieldArr(), fields)
|
||||
if len(fvs) > 0 {
|
||||
fvals := make([]resp.Value, 0, len(fvs)*2)
|
||||
if msg.OutputType == JSON {
|
||||
|
|
|
@ -485,7 +485,7 @@ func (sw *scanWriter) writeObject(opts ScanWriterParams) bool {
|
|||
}
|
||||
|
||||
if sw.hasFieldsOutput() {
|
||||
fvs := orderFields(sw.fmap, opts.fields)
|
||||
fvs := orderFields(sw.fmap, sw.farr, opts.fields)
|
||||
if len(fvs) > 0 {
|
||||
fvals := make([]resp.Value, 0, len(fvs)*2)
|
||||
for i, fv := range fvs {
|
||||
|
|
Loading…
Reference in New Issue