Skip to content

Commit f43effa

Browse files
authored
Reduce map lookup in ColumnTypeDatabaseTypeName. (#1436)
1 parent 99976f4 commit f43effa

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

collations.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
package mysql
1010

1111
const defaultCollation = "utf8mb4_general_ci"
12-
const binaryCollation = "binary"
12+
const binaryCollationID = 63
1313

1414
// A list of available collations mapped to the internal ID.
1515
// To update this map use the following MySQL query:

fields.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ func (mf *mysqlField) typeDatabaseName() string {
1818
case fieldTypeBit:
1919
return "BIT"
2020
case fieldTypeBLOB:
21-
if mf.charSet != collations[binaryCollation] {
21+
if mf.charSet != binaryCollationID {
2222
return "TEXT"
2323
}
2424
return "BLOB"
@@ -49,7 +49,7 @@ func (mf *mysqlField) typeDatabaseName() string {
4949
}
5050
return "INT"
5151
case fieldTypeLongBLOB:
52-
if mf.charSet != collations[binaryCollation] {
52+
if mf.charSet != binaryCollationID {
5353
return "LONGTEXT"
5454
}
5555
return "LONGBLOB"
@@ -59,7 +59,7 @@ func (mf *mysqlField) typeDatabaseName() string {
5959
}
6060
return "BIGINT"
6161
case fieldTypeMediumBLOB:
62-
if mf.charSet != collations[binaryCollation] {
62+
if mf.charSet != binaryCollationID {
6363
return "MEDIUMTEXT"
6464
}
6565
return "MEDIUMBLOB"
@@ -77,7 +77,7 @@ func (mf *mysqlField) typeDatabaseName() string {
7777
}
7878
return "SMALLINT"
7979
case fieldTypeString:
80-
if mf.charSet == collations[binaryCollation] {
80+
if mf.charSet == binaryCollationID {
8181
return "BINARY"
8282
}
8383
return "CHAR"
@@ -91,17 +91,17 @@ func (mf *mysqlField) typeDatabaseName() string {
9191
}
9292
return "TINYINT"
9393
case fieldTypeTinyBLOB:
94-
if mf.charSet != collations[binaryCollation] {
94+
if mf.charSet != binaryCollationID {
9595
return "TINYTEXT"
9696
}
9797
return "TINYBLOB"
9898
case fieldTypeVarChar:
99-
if mf.charSet == collations[binaryCollation] {
99+
if mf.charSet == binaryCollationID {
100100
return "VARBINARY"
101101
}
102102
return "VARCHAR"
103103
case fieldTypeVarString:
104-
if mf.charSet == collations[binaryCollation] {
104+
if mf.charSet == binaryCollationID {
105105
return "VARBINARY"
106106
}
107107
return "VARCHAR"
@@ -194,7 +194,7 @@ func (mf *mysqlField) scanType() reflect.Type {
194194

195195
case fieldTypeBit, fieldTypeTinyBLOB, fieldTypeMediumBLOB, fieldTypeLongBLOB,
196196
fieldTypeBLOB, fieldTypeVarString, fieldTypeString, fieldTypeGeometry:
197-
if mf.charSet == 63 /* binary */ {
197+
if mf.charSet == binaryCollationID {
198198
return scanTypeBytes
199199
}
200200
fallthrough

0 commit comments

Comments
 (0)