From 3fbf8c8fc8a6cb8837ec492c37a94a3861318357 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=B6ksel=20K=C3=BC=C3=A7=C3=BCk=C5=9Fahin?= Date: Sat, 1 Jun 2024 20:01:21 +0300 Subject: [PATCH] feature: change for range over slice to for-i --- benchmarks/aggs_example_test.go | 2 +- es/types.go | 27 +++++++++++++-------------- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/benchmarks/aggs_example_test.go b/benchmarks/aggs_example_test.go index adc77a7..d490c42 100644 --- a/benchmarks/aggs_example_test.go +++ b/benchmarks/aggs_example_test.go @@ -1,4 +1,4 @@ -package benchmarks +package benchmarks_test import ( "encoding/json" diff --git a/es/types.go b/es/types.go index b69855b..2fdc887 100644 --- a/es/types.go +++ b/es/types.go @@ -64,9 +64,8 @@ func correctType(b any) (any, bool) { return Object{"bool": b}, true case rangeType: return Object{"range": b}, true - default: - return b, true } + return b, true } func NewQuery(c any) Object { @@ -106,8 +105,8 @@ func (b boolType) Filter(items ...any) boolType { if !exists { filter = filterType{} } - for _, item := range items { - if field, ok := correctType(item); ok { + for i := 0; i < len(items); i++ { + if field, ok := correctType(items[i]); ok { filter = append(filter.(filterType), field) } } @@ -120,8 +119,8 @@ func (b boolType) Must(items ...any) boolType { if !exists { must = mustType{} } - for _, item := range items { - if field, ok := correctType(item); ok { + for i := 0; i < len(items); i++ { + if field, ok := correctType(items[i]); ok { must = append(must.(mustType), field) } } @@ -134,8 +133,8 @@ func (b boolType) MustNot(items ...any) boolType { if !exists { mustNot = mustNotType{} } - for _, item := range items { - if field, ok := correctType(item); ok { + for i := 0; i < len(items); i++ { + if field, ok := correctType(items[i]); ok { mustNot = append(mustNot.(mustNotType), field) } } @@ -148,8 +147,8 @@ func (b boolType) Should(items ...any) boolType { if !exists { should = shouldType{} } - for _, item := range items { - if field, ok := correctType(item); ok { + for i := 0; i < len(items); i++ { + if field, ok := correctType(items[i]); ok { should = append(should.(shouldType), field) } } @@ -216,8 +215,8 @@ func (s sourceType) Includes(fields ...string) sourceType { if !exists { includes = includesType{} } - for _, field := range fields { - includes = append(includes.(includesType), field) + for i := 0; i < len(fields); i++ { + includes = append(includes.(includesType), fields[i]) } s["includes"] = includes return s @@ -228,8 +227,8 @@ func (s sourceType) Excludes(fields ...string) sourceType { if !exists { excludes = excludesType{} } - for _, field := range fields { - excludes = append(excludes.(excludesType), field) + for i := 0; i < len(fields); i++ { + excludes = append(excludes.(excludesType), fields[i]) } s["excludes"] = excludes return s