Uses struct{}{} instead of bool for sets via map

This commit is contained in:
Jitendra Ojha 2020-02-21 12:18:55 +05:30
parent 20cb84ca8d
commit 56557cca5b

View File

@ -1324,7 +1324,8 @@ func (scope *Scope) autoIndex() *Scope {
} }
func (scope *Scope) getColumnAsArray(columns []string, values ...interface{}) (results [][]interface{}) { func (scope *Scope) getColumnAsArray(columns []string, values ...interface{}) (results [][]interface{}) {
resultMap := make(map[string]bool) keyExists := struct{}{}
resultsKeys := make(map[string]struct{})
for _, value := range values { for _, value := range values {
indirectValue := indirect(reflect.ValueOf(value)) indirectValue := indirect(reflect.ValueOf(value))
@ -1344,8 +1345,8 @@ func (scope *Scope) getColumnAsArray(columns []string, values ...interface{}) (r
if hasValue { if hasValue {
h := fmt.Sprint(result...) h := fmt.Sprint(result...)
if _, exist := resultMap[h]; !exist { if _, exist := resultsKeys[h]; !exist {
resultMap[h] = true resultsKeys[h] = keyExists
results = append(results, result) results = append(results, result)
} }
} }
@ -1363,8 +1364,8 @@ func (scope *Scope) getColumnAsArray(columns []string, values ...interface{}) (r
if hasValue { if hasValue {
h := fmt.Sprint(result...) h := fmt.Sprint(result...)
if _, exist := resultMap[h]; !exist { if _, exist := resultsKeys[h]; !exist {
resultMap[h] = true resultsKeys[h] = keyExists
results = append(results, result) results = append(results, result)
} }
} }