From 2b4097577d6fa870df37e71507b310117f8d4b27 Mon Sep 17 00:00:00 2001 From: Koichi Shiraishi Date: Mon, 23 Nov 2020 14:13:45 +0900 Subject: [PATCH] Pass expression to unsafe.Pointer directly --- decode_array.go | 6 ++---- decode_slice.go | 6 ++---- decode_struct.go | 6 ++---- 3 files changed, 6 insertions(+), 12 deletions(-) diff --git a/decode_array.go b/decode_array.go index c333a05..9ea73ec 100644 --- a/decode_array.go +++ b/decode_array.go @@ -31,8 +31,7 @@ func (d *arrayDecoder) decodeStream(s *stream, p unsafe.Pointer) error { idx := 0 for { s.cursor++ - addr := uintptr(p) + uintptr(idx)*d.size - if err := d.valueDecoder.decodeStream(s, *(*unsafe.Pointer)(unsafe.Pointer(&addr))); err != nil { + if err := d.valueDecoder.decodeStream(s, unsafe.Pointer(uintptr(p)+uintptr(idx)*d.size)); err != nil { return err } s.skipWhiteSpace() @@ -91,8 +90,7 @@ func (d *arrayDecoder) decode(buf []byte, cursor int64, p unsafe.Pointer) (int64 idx := 0 for { cursor++ - addr := uintptr(p) + uintptr(idx)*d.size - c, err := d.valueDecoder.decode(buf, cursor, *(*unsafe.Pointer)(unsafe.Pointer(&addr))) + c, err := d.valueDecoder.decode(buf, cursor, unsafe.Pointer(uintptr(p)+uintptr(idx)*d.size)) if err != nil { return 0, err } diff --git a/decode_slice.go b/decode_slice.go index 6269dfb..ff17914 100644 --- a/decode_slice.go +++ b/decode_slice.go @@ -90,8 +90,7 @@ func (d *sliceDecoder) decodeStream(s *stream, p unsafe.Pointer) error { dst := sliceHeader{data: data, len: idx, cap: cap} copySlice(d.elemType, dst, src) } - addr := uintptr(data) + uintptr(idx)*d.size - if err := d.valueDecoder.decodeStream(s, *(*unsafe.Pointer)(unsafe.Pointer(&addr))); err != nil { + if err := d.valueDecoder.decodeStream(s, unsafe.Pointer(uintptr(data)+uintptr(idx)*d.size)); err != nil { return err } 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} copySlice(d.elemType, dst, src) } - addr := uintptr(data) + uintptr(idx)*d.size - c, err := d.valueDecoder.decode(buf, cursor, *(*unsafe.Pointer)(unsafe.Pointer(&addr))) + c, err := d.valueDecoder.decode(buf, cursor, unsafe.Pointer(uintptr(data)+uintptr(idx)*d.size)) if err != nil { return 0, err } diff --git a/decode_struct.go b/decode_struct.go index 2bc8f46..19990e9 100644 --- a/decode_struct.go +++ b/decode_struct.go @@ -54,8 +54,7 @@ func (d *structDecoder) decodeStream(s *stream, p unsafe.Pointer) error { k := *(*string)(unsafe.Pointer(&key)) field, exists := d.fieldMap[k] if exists { - addr := uintptr(p) + field.offset - if err := field.dec.decodeStream(s, *(*unsafe.Pointer)(unsafe.Pointer(&addr))); err != nil { + if err := field.dec.decodeStream(s, unsafe.Pointer(uintptr(p)+field.offset)); err != nil { return err } } 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)) field, exists := d.fieldMap[k] if exists { - addr := uintptr(p) + field.offset - c, err := field.dec.decode(buf, cursor, *(*unsafe.Pointer)(unsafe.Pointer(&addr))) + c, err := field.dec.decode(buf, cursor, unsafe.Pointer(uintptr(p)+field.offset)) if err != nil { return 0, err }