bencode: Remove string allocation when parsing strings
This commit is contained in:
parent
2b1068885c
commit
c5cc570e42
|
@ -10,6 +10,7 @@ import (
|
|||
"runtime"
|
||||
"strconv"
|
||||
"strings"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
type Decoder struct {
|
||||
|
@ -404,7 +405,11 @@ func (d *Decoder) readOneValue() bool {
|
|||
if b >= '0' && b <= '9' {
|
||||
start := d.buf.Len() - 1
|
||||
d.readUntil(':')
|
||||
length, err := strconv.ParseInt(d.buf.String()[start:], 10, 64)
|
||||
s := reflect.StringHeader{
|
||||
uintptr(unsafe.Pointer(&d.buf.Bytes()[start])),
|
||||
d.buf.Len() - start,
|
||||
}
|
||||
length, err := strconv.ParseInt(*(*string)(unsafe.Pointer(&s)), 10, 64)
|
||||
checkForIntParseError(err, d.Offset-1)
|
||||
|
||||
d.buf.WriteString(":")
|
||||
|
|
Loading…
Reference in New Issue