Avoid extra type assertion on native type Scan path
Before: BenchmarkConnInfoScanInt4IntoBinaryDecoder-16 89744814 12.5 ns/op 0 B/op 0 allocs/op BenchmarkConnInfoScanInt4IntoGoInt32-16 27688370 41.1 ns/op 0 B/op 0 allocs/op After: BenchmarkConnInfoScanInt4IntoBinaryDecoder-16 88181061 12.4 ns/op 0 B/op 0 allocs/op BenchmarkConnInfoScanInt4IntoGoInt32-16 30402768 36.8 ns/op 0 B/op 0 allocs/op
This commit is contained in:
@@ -337,12 +337,17 @@ func (ci *ConnInfo) DeepCopy() *ConnInfo {
|
||||
}
|
||||
|
||||
func (ci *ConnInfo) Scan(oid uint32, formatCode int16, buf []byte, dest interface{}) error {
|
||||
if dest, ok := dest.(BinaryDecoder); ok && formatCode == BinaryFormatCode {
|
||||
return dest.DecodeBinary(ci, buf)
|
||||
}
|
||||
|
||||
if dest, ok := dest.(TextDecoder); ok && formatCode == TextFormatCode {
|
||||
return dest.DecodeText(ci, buf)
|
||||
switch formatCode {
|
||||
case BinaryFormatCode:
|
||||
if dest, ok := dest.(BinaryDecoder); ok {
|
||||
return dest.DecodeBinary(ci, buf)
|
||||
}
|
||||
case TextFormatCode:
|
||||
if dest, ok := dest.(TextDecoder); ok {
|
||||
return dest.DecodeText(ci, buf)
|
||||
}
|
||||
default:
|
||||
return errors.Errorf("unknown format code: %v", formatCode)
|
||||
}
|
||||
|
||||
if dt, ok := ci.DataTypeForOID(oid); ok {
|
||||
@@ -366,8 +371,6 @@ func (ci *ConnInfo) Scan(oid uint32, formatCode int16, buf []byte, dest interfac
|
||||
} else {
|
||||
return errors.Errorf("%T is not a pgtype.BinaryDecoder", value)
|
||||
}
|
||||
default:
|
||||
return errors.Errorf("unknown format code: %v", formatCode)
|
||||
}
|
||||
|
||||
if scanner, ok := dest.(sql.Scanner); ok {
|
||||
|
||||
Reference in New Issue
Block a user