minor performance optz

This commit is contained in:
Josh Baker 2016-08-21 10:10:55 -07:00
parent cec0cb946f
commit 29fecf859f
1 changed files with 10 additions and 9 deletions

View File

@ -82,6 +82,9 @@ func (t Result) Exists() bool {
// nil, for JSON null // nil, for JSON null
// //
func (t Result) Value() interface{} { func (t Result) Value() interface{} {
if t.Type == String {
return t.Str
}
switch t.Type { switch t.Type {
default: default:
return nil return nil
@ -89,8 +92,6 @@ func (t Result) Value() interface{} {
return false return false
case Number: case Number:
return t.Num return t.Num
case String:
return t.Str
case Multi: case Multi:
var res = make([]interface{}, len(t.Multi)) var res = make([]interface{}, len(t.Multi))
for i, v := range t.Multi { for i, v := range t.Multi {
@ -697,15 +698,16 @@ func (t Result) Less(token Result, caseSensitive bool) bool {
if t.Type > token.Type { if t.Type > token.Type {
return false return false
} }
switch t.Type { if t.Type == String {
default:
return t.Raw < token.Raw
case String:
if caseSensitive { if caseSensitive {
return t.Str < token.Str return t.Str < token.Str
} }
return stringLessInsensitive(t.Str, token.Str) return stringLessInsensitive(t.Str, token.Str)
case Multi: }
if t.Type == Number {
return t.Num < token.Num
}
if t.Type == Multi {
for i := 0; i < len(t.Multi) && i < len(token.Multi); i++ { for i := 0; i < len(t.Multi) && i < len(token.Multi); i++ {
if t.Multi[i].Less(token.Multi[i], caseSensitive) { if t.Multi[i].Less(token.Multi[i], caseSensitive) {
return true return true
@ -715,9 +717,8 @@ func (t Result) Less(token Result, caseSensitive bool) bool {
} }
} }
return len(t.Multi) < len(token.Multi) return len(t.Multi) < len(token.Multi)
case Number:
return t.Num < token.Num
} }
return t.Raw < token.Raw
} }
func stringLessInsensitive(a, b string) bool { func stringLessInsensitive(a, b string) bool {