Skip to content

Commit 751c1d6

Browse files
19118605381911860538
andauthored
perf(schema): avoid redundant strings.ToLower call (#7464)
Co-authored-by: 1911860538 <[email protected]>
1 parent 8e7ab46 commit 751c1d6

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

schema/field.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -318,9 +318,10 @@ func (schema *Schema) ParseField(fieldStruct reflect.StructField) *Field {
318318
}
319319

320320
if val, ok := field.TagSettings["TYPE"]; ok {
321-
switch DataType(strings.ToLower(val)) {
321+
lowerVal := DataType(strings.ToLower(val))
322+
switch lowerVal {
322323
case Bool, Int, Uint, Float, String, Time, Bytes:
323-
field.DataType = DataType(strings.ToLower(val))
324+
field.DataType = lowerVal
324325
default:
325326
field.DataType = DataType(val)
326327
}

schema/relationship.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -763,8 +763,9 @@ func (rel *Relationship) ToQueryConditions(ctx context.Context, reflectValue ref
763763
}
764764

765765
func copyableDataType(str DataType) bool {
766+
lowerStr := strings.ToLower(string(str))
766767
for _, s := range []string{"auto_increment", "primary key"} {
767-
if strings.Contains(strings.ToLower(string(str)), s) {
768+
if strings.Contains(lowerStr, s) {
768769
return false
769770
}
770771
}

0 commit comments

Comments
 (0)