Small optimizations.

This commit is contained in:
go-jet 2023-04-14 12:20:36 +02:00
parent 73d7e4823c
commit 65e02fa87d
2 changed files with 22 additions and 10 deletions

View file

@ -122,9 +122,9 @@ func (s *ScanContext) getTypeInfo(structType reflect.Type, parentField *reflect.
} }
type groupKeyInfo struct { type groupKeyInfo struct {
typeName string typeName string
indexes []int pkIndexes []int
subTypes []groupKeyInfo subTypes []groupKeyInfo
} }
func (s *ScanContext) getGroupKey(structType reflect.Type, structField *reflect.StructField) string { func (s *ScanContext) getGroupKey(structType reflect.Type, structField *reflect.StructField) string {
@ -148,13 +148,13 @@ func (s *ScanContext) getGroupKey(structType reflect.Type, structField *reflect.
} }
func (s *ScanContext) constructGroupKey(groupKeyInfo groupKeyInfo) string { func (s *ScanContext) constructGroupKey(groupKeyInfo groupKeyInfo) string {
if len(groupKeyInfo.indexes) == 0 && len(groupKeyInfo.subTypes) == 0 { if len(groupKeyInfo.pkIndexes) == 0 && len(groupKeyInfo.subTypes) == 0 {
return fmt.Sprintf("|ROW:%d|", s.rowNum) return fmt.Sprintf("|ROW:%d|", s.rowNum)
} }
var groupKeys []string var groupKeys []string
for _, index := range groupKeyInfo.indexes { for _, index := range groupKeyInfo.pkIndexes {
groupKeys = append(groupKeys, s.rowElemToString(index)) groupKeys = append(groupKeys, s.rowElemToString(index))
} }
@ -190,19 +190,19 @@ func (s *ScanContext) getGroupKeyInfo(
if isPrimaryKey(field, primaryKeyOverwrites) { if isPrimaryKey(field, primaryKeyOverwrites) {
newTypeName, fieldName := getTypeAndFieldName(typeName, field) newTypeName, fieldName := getTypeAndFieldName(typeName, field)
index := s.typeToColumnIndex(newTypeName, fieldName) pkIndex := s.typeToColumnIndex(newTypeName, fieldName)
if index < 0 { if pkIndex < 0 {
continue continue
} }
ret.indexes = append(ret.indexes, index) ret.pkIndexes = append(ret.pkIndexes, pkIndex)
} else if fieldType.Kind() == reflect.Struct { } else if fieldType.Kind() == reflect.Struct && fieldType != timeType {
subType := s.getGroupKeyInfo(fieldType, &field, typeVisited) subType := s.getGroupKeyInfo(fieldType, &field, typeVisited)
if len(subType.indexes) != 0 || len(subType.subTypes) != 0 { if len(subType.pkIndexes) != 0 || len(subType.subTypes) != 0 {
ret.subTypes = append(ret.subTypes, subType) ret.subTypes = append(ret.subTypes, subType)
} }
} }

View file

@ -360,8 +360,20 @@ func cloneBytes(b []byte) []byte {
func concat(stringList ...string) string { func concat(stringList ...string) string {
var b strings.Builder var b strings.Builder
b.Grow(length(stringList))
for _, str := range stringList { for _, str := range stringList {
b.WriteString(str) b.WriteString(str)
} }
return b.String() return b.String()
} }
func length(strings []string) int {
var ret int
for i := 0; i < len(strings); i++ {
ret += len(strings[i])
}
return ret
}