Skip to content

Commit

Permalink
Reduce map lookup in ColumnTypeDatabaseTypeName. (#1436)
Browse files Browse the repository at this point in the history
  • Loading branch information
methane authored May 27, 2023
1 parent 99976f4 commit f43effa
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion collations.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
package mysql

const defaultCollation = "utf8mb4_general_ci"
const binaryCollation = "binary"
const binaryCollationID = 63

// A list of available collations mapped to the internal ID.
// To update this map use the following MySQL query:
Expand Down
16 changes: 8 additions & 8 deletions fields.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func (mf *mysqlField) typeDatabaseName() string {
case fieldTypeBit:
return "BIT"
case fieldTypeBLOB:
if mf.charSet != collations[binaryCollation] {
if mf.charSet != binaryCollationID {
return "TEXT"
}
return "BLOB"
Expand Down Expand Up @@ -49,7 +49,7 @@ func (mf *mysqlField) typeDatabaseName() string {
}
return "INT"
case fieldTypeLongBLOB:
if mf.charSet != collations[binaryCollation] {
if mf.charSet != binaryCollationID {
return "LONGTEXT"
}
return "LONGBLOB"
Expand All @@ -59,7 +59,7 @@ func (mf *mysqlField) typeDatabaseName() string {
}
return "BIGINT"
case fieldTypeMediumBLOB:
if mf.charSet != collations[binaryCollation] {
if mf.charSet != binaryCollationID {
return "MEDIUMTEXT"
}
return "MEDIUMBLOB"
Expand All @@ -77,7 +77,7 @@ func (mf *mysqlField) typeDatabaseName() string {
}
return "SMALLINT"
case fieldTypeString:
if mf.charSet == collations[binaryCollation] {
if mf.charSet == binaryCollationID {
return "BINARY"
}
return "CHAR"
Expand All @@ -91,17 +91,17 @@ func (mf *mysqlField) typeDatabaseName() string {
}
return "TINYINT"
case fieldTypeTinyBLOB:
if mf.charSet != collations[binaryCollation] {
if mf.charSet != binaryCollationID {
return "TINYTEXT"
}
return "TINYBLOB"
case fieldTypeVarChar:
if mf.charSet == collations[binaryCollation] {
if mf.charSet == binaryCollationID {
return "VARBINARY"
}
return "VARCHAR"
case fieldTypeVarString:
if mf.charSet == collations[binaryCollation] {
if mf.charSet == binaryCollationID {
return "VARBINARY"
}
return "VARCHAR"
Expand Down Expand Up @@ -194,7 +194,7 @@ func (mf *mysqlField) scanType() reflect.Type {

case fieldTypeBit, fieldTypeTinyBLOB, fieldTypeMediumBLOB, fieldTypeLongBLOB,
fieldTypeBLOB, fieldTypeVarString, fieldTypeString, fieldTypeGeometry:
if mf.charSet == 63 /* binary */ {
if mf.charSet == binaryCollationID {
return scanTypeBytes
}
fallthrough
Expand Down

0 comments on commit f43effa

Please sign in to comment.