2
0
mirror of synced 2025-02-23 22:28:11 +00:00

bencode: Avoid Value.Interface call testing for big.Int

Was resulting in significant allocation.
This commit is contained in:
Matt Joiner 2018-07-17 21:25:15 +10:00
parent 216cb7e356
commit b00711bb68

View File

@ -105,16 +105,18 @@ func (e *Encoder) reflectMarshaler(v reflect.Value) bool {
return false
}
var bigIntType = reflect.TypeOf(big.Int{})
func (e *Encoder) reflectValue(v reflect.Value) {
if e.reflectMarshaler(v) {
return
}
switch t := v.Interface().(type) {
case big.Int:
if v.Type() == bigIntType {
e.writeString("i")
e.writeString(t.String())
bi := v.Interface().(big.Int)
e.writeString(bi.String())
e.writeString("e")
return
}