Skip to content

Commit

Permalink
Small optimizations.
Browse files Browse the repository at this point in the history
  • Loading branch information
go-jet committed Apr 14, 2023
1 parent 73d7e48 commit 65e02fa
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
20 changes: 10 additions & 10 deletions qrm/scan_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,9 @@ func (s *ScanContext) getTypeInfo(structType reflect.Type, parentField *reflect.
}

type groupKeyInfo struct {
typeName string
indexes []int
subTypes []groupKeyInfo
typeName string
pkIndexes []int
subTypes []groupKeyInfo
}

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

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)
}

var groupKeys []string

for _, index := range groupKeyInfo.indexes {
for _, index := range groupKeyInfo.pkIndexes {
groupKeys = append(groupKeys, s.rowElemToString(index))
}

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

index := s.typeToColumnIndex(newTypeName, fieldName)
pkIndex := s.typeToColumnIndex(newTypeName, fieldName)

if index < 0 {
if pkIndex < 0 {
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)

if len(subType.indexes) != 0 || len(subType.subTypes) != 0 {
if len(subType.pkIndexes) != 0 || len(subType.subTypes) != 0 {
ret.subTypes = append(ret.subTypes, subType)
}
}
Expand Down
12 changes: 12 additions & 0 deletions qrm/utill.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,8 +360,20 @@ func cloneBytes(b []byte) []byte {

func concat(stringList ...string) string {
var b strings.Builder
b.Grow(length(stringList))

for _, str := range stringList {
b.WriteString(str)
}
return b.String()
}

func length(strings []string) int {
var ret int

for i := 0; i < len(strings); i++ {
ret += len(strings[i])
}

return ret
}

0 comments on commit 65e02fa

Please sign in to comment.