Skip to content

Commit 65e02fa

Browse files
committed
Small optimizations.
1 parent 73d7e48 commit 65e02fa

2 files changed

Lines changed: 22 additions & 10 deletions

File tree

qrm/scan_context.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,9 @@ func (s *ScanContext) getTypeInfo(structType reflect.Type, parentField *reflect.
122122
}
123123

124124
type groupKeyInfo struct {
125-
typeName string
126-
indexes []int
127-
subTypes []groupKeyInfo
125+
typeName string
126+
pkIndexes []int
127+
subTypes []groupKeyInfo
128128
}
129129

130130
func (s *ScanContext) getGroupKey(structType reflect.Type, structField *reflect.StructField) string {
@@ -148,13 +148,13 @@ func (s *ScanContext) getGroupKey(structType reflect.Type, structField *reflect.
148148
}
149149

150150
func (s *ScanContext) constructGroupKey(groupKeyInfo groupKeyInfo) string {
151-
if len(groupKeyInfo.indexes) == 0 && len(groupKeyInfo.subTypes) == 0 {
151+
if len(groupKeyInfo.pkIndexes) == 0 && len(groupKeyInfo.subTypes) == 0 {
152152
return fmt.Sprintf("|ROW:%d|", s.rowNum)
153153
}
154154

155155
var groupKeys []string
156156

157-
for _, index := range groupKeyInfo.indexes {
157+
for _, index := range groupKeyInfo.pkIndexes {
158158
groupKeys = append(groupKeys, s.rowElemToString(index))
159159
}
160160

@@ -190,19 +190,19 @@ func (s *ScanContext) getGroupKeyInfo(
190190
if isPrimaryKey(field, primaryKeyOverwrites) {
191191
newTypeName, fieldName := getTypeAndFieldName(typeName, field)
192192

193-
index := s.typeToColumnIndex(newTypeName, fieldName)
193+
pkIndex := s.typeToColumnIndex(newTypeName, fieldName)
194194

195-
if index < 0 {
195+
if pkIndex < 0 {
196196
continue
197197
}
198198

199-
ret.indexes = append(ret.indexes, index)
199+
ret.pkIndexes = append(ret.pkIndexes, pkIndex)
200200

201-
} else if fieldType.Kind() == reflect.Struct {
201+
} else if fieldType.Kind() == reflect.Struct && fieldType != timeType {
202202

203203
subType := s.getGroupKeyInfo(fieldType, &field, typeVisited)
204204

205-
if len(subType.indexes) != 0 || len(subType.subTypes) != 0 {
205+
if len(subType.pkIndexes) != 0 || len(subType.subTypes) != 0 {
206206
ret.subTypes = append(ret.subTypes, subType)
207207
}
208208
}

qrm/utill.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,8 +360,20 @@ func cloneBytes(b []byte) []byte {
360360

361361
func concat(stringList ...string) string {
362362
var b strings.Builder
363+
b.Grow(length(stringList))
364+
363365
for _, str := range stringList {
364366
b.WriteString(str)
365367
}
366368
return b.String()
367369
}
370+
371+
func length(strings []string) int {
372+
var ret int
373+
374+
for i := 0; i < len(strings); i++ {
375+
ret += len(strings[i])
376+
}
377+
378+
return ret
379+
}

0 commit comments

Comments
 (0)