bencode: Avoid Value.Interface call testing for big.Int
Was resulting in significant allocation.
This commit is contained in:
parent
216cb7e356
commit
b00711bb68
@ -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
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user