Pass expression to unsafe.Pointer directly

This commit is contained in:
Koichi Shiraishi 2020-11-23 14:13:45 +09:00
parent e4214835d8
commit 2b4097577d
No known key found for this signature in database
GPG Key ID: A71DFD3B4DA7A79B
3 changed files with 6 additions and 12 deletions

View File

@ -31,8 +31,7 @@ func (d *arrayDecoder) decodeStream(s *stream, p unsafe.Pointer) error {
idx := 0 idx := 0
for { for {
s.cursor++ s.cursor++
addr := uintptr(p) + uintptr(idx)*d.size if err := d.valueDecoder.decodeStream(s, unsafe.Pointer(uintptr(p)+uintptr(idx)*d.size)); err != nil {
if err := d.valueDecoder.decodeStream(s, *(*unsafe.Pointer)(unsafe.Pointer(&addr))); err != nil {
return err return err
} }
s.skipWhiteSpace() s.skipWhiteSpace()
@ -91,8 +90,7 @@ func (d *arrayDecoder) decode(buf []byte, cursor int64, p unsafe.Pointer) (int64
idx := 0 idx := 0
for { for {
cursor++ cursor++
addr := uintptr(p) + uintptr(idx)*d.size c, err := d.valueDecoder.decode(buf, cursor, unsafe.Pointer(uintptr(p)+uintptr(idx)*d.size))
c, err := d.valueDecoder.decode(buf, cursor, *(*unsafe.Pointer)(unsafe.Pointer(&addr)))
if err != nil { if err != nil {
return 0, err return 0, err
} }

View File

@ -90,8 +90,7 @@ func (d *sliceDecoder) decodeStream(s *stream, p unsafe.Pointer) error {
dst := sliceHeader{data: data, len: idx, cap: cap} dst := sliceHeader{data: data, len: idx, cap: cap}
copySlice(d.elemType, dst, src) copySlice(d.elemType, dst, src)
} }
addr := uintptr(data) + uintptr(idx)*d.size if err := d.valueDecoder.decodeStream(s, unsafe.Pointer(uintptr(data)+uintptr(idx)*d.size)); err != nil {
if err := d.valueDecoder.decodeStream(s, *(*unsafe.Pointer)(unsafe.Pointer(&addr))); err != nil {
return err return err
} }
s.skipWhiteSpace() s.skipWhiteSpace()
@ -191,8 +190,7 @@ func (d *sliceDecoder) decode(buf []byte, cursor int64, p unsafe.Pointer) (int64
dst := sliceHeader{data: data, len: idx, cap: cap} dst := sliceHeader{data: data, len: idx, cap: cap}
copySlice(d.elemType, dst, src) copySlice(d.elemType, dst, src)
} }
addr := uintptr(data) + uintptr(idx)*d.size c, err := d.valueDecoder.decode(buf, cursor, unsafe.Pointer(uintptr(data)+uintptr(idx)*d.size))
c, err := d.valueDecoder.decode(buf, cursor, *(*unsafe.Pointer)(unsafe.Pointer(&addr)))
if err != nil { if err != nil {
return 0, err return 0, err
} }

View File

@ -54,8 +54,7 @@ func (d *structDecoder) decodeStream(s *stream, p unsafe.Pointer) error {
k := *(*string)(unsafe.Pointer(&key)) k := *(*string)(unsafe.Pointer(&key))
field, exists := d.fieldMap[k] field, exists := d.fieldMap[k]
if exists { if exists {
addr := uintptr(p) + field.offset if err := field.dec.decodeStream(s, unsafe.Pointer(uintptr(p)+field.offset)); err != nil {
if err := field.dec.decodeStream(s, *(*unsafe.Pointer)(unsafe.Pointer(&addr))); err != nil {
return err return err
} }
} else if s.disallowUnknownFields { } else if s.disallowUnknownFields {
@ -109,8 +108,7 @@ func (d *structDecoder) decode(buf []byte, cursor int64, p unsafe.Pointer) (int6
k := *(*string)(unsafe.Pointer(&key)) k := *(*string)(unsafe.Pointer(&key))
field, exists := d.fieldMap[k] field, exists := d.fieldMap[k]
if exists { if exists {
addr := uintptr(p) + field.offset c, err := field.dec.decode(buf, cursor, unsafe.Pointer(uintptr(p)+field.offset))
c, err := field.dec.decode(buf, cursor, *(*unsafe.Pointer)(unsafe.Pointer(&addr)))
if err != nil { if err != nil {
return 0, err return 0, err
} }