Skip to content

Commit e0e6456

Browse files
committed
Small performance improvements
1 parent a81ba17 commit e0e6456

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

query.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,15 +83,15 @@ func (t Term) build() (interface{}, error) {
8383
}
8484
}
8585

86-
args := []interface{}{}
87-
optArgs := map[string]interface{}{}
86+
args := make([]interface{}, len(t.args))
87+
optArgs := make(map[string]interface{}, len(t.optArgs))
8888

89-
for _, v := range t.args {
89+
for i, v := range t.args {
9090
arg, err := v.build()
9191
if err != nil {
9292
return nil, err
9393
}
94-
args = append(args, arg)
94+
args[i] = arg
9595
}
9696

9797
for k, v := range t.optArgs {

utils.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,10 @@ func optArgsToMap(optArgs OptArgs) map[string]interface{} {
173173

174174
// Convert a list into a slice of terms
175175
func convertTermList(l []interface{}) termsList {
176+
if len(l) == 0 {
177+
return nil
178+
}
179+
176180
terms := make(termsList, len(l))
177181
for i, v := range l {
178182
terms[i] = Expr(v)
@@ -183,6 +187,10 @@ func convertTermList(l []interface{}) termsList {
183187

184188
// Convert a map into a map of terms
185189
func convertTermObj(o map[string]interface{}) termsObj {
190+
if len(o) == 0 {
191+
return nil
192+
}
193+
186194
terms := make(termsObj, len(o))
187195
for k, v := range o {
188196
terms[k] = Expr(v)

0 commit comments

Comments
 (0)