diff options
author | Ayke van Laethem <[email protected]> | 2023-05-13 14:23:29 +0200 |
---|---|---|
committer | Ron Evans <[email protected]> | 2023-05-14 18:23:23 +0200 |
commit | 535e64adbcc1c0907c18a25c7f149c31cb69e708 (patch) | |
tree | 2be707b7a57049cc1fbb378c33c29f2e716982a0 /src/reflect | |
parent | af936f3261f30904d71d0ab88364ed4f6277324d (diff) | |
download | tinygo-535e64adbcc1c0907c18a25c7f149c31cb69e708.tar.gz tinygo-535e64adbcc1c0907c18a25c7f149c31cb69e708.zip |
reflect: optimize Zero() a little bit
It could be expensive to call Size() three times, and it is unnecessary.
Instead, do it only once.
This results in a very small reduction of binary size if Zero() is used.
Diffstat (limited to 'src/reflect')
-rw-r--r-- | src/reflect/value.go | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/src/reflect/value.go b/src/reflect/value.go index bd8c1476a..96cbcb804 100644 --- a/src/reflect/value.go +++ b/src/reflect/value.go @@ -1486,7 +1486,8 @@ func init() { } func Zero(typ Type) Value { - if typ.Size() <= unsafe.Sizeof(uintptr(0)) { + size := typ.Size() + if size <= unsafe.Sizeof(uintptr(0)) { return Value{ typecode: typ.(*rawType), value: nil, @@ -1494,7 +1495,7 @@ func Zero(typ Type) Value { } } - if typ.Size() <= zerobufferLen { + if size <= zerobufferLen { return Value{ typecode: typ.(*rawType), value: unsafe.Pointer(zerobuffer), @@ -1504,7 +1505,7 @@ func Zero(typ Type) Value { return Value{ typecode: typ.(*rawType), - value: alloc(typ.Size(), nil), + value: alloc(size, nil), flags: valueFlagExported | valueFlagRO, } } |