aboutsummaryrefslogtreecommitdiff
path: root/src/encoding/binary/binary.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/encoding/binary/binary.go')
-rw-r--r--src/encoding/binary/binary.go13
1 files changed, 11 insertions, 2 deletions
diff --git a/src/encoding/binary/binary.go b/src/encoding/binary/binary.go
index 59a6c654d2..634995a5bd 100644
--- a/src/encoding/binary/binary.go
+++ b/src/encoding/binary/binary.go
@@ -480,8 +480,17 @@ var structSize sync.Map // map[reflect.Type]int
func dataSize(v reflect.Value) int {
switch v.Kind() {
case reflect.Slice:
- if s := sizeof(v.Type().Elem()); s >= 0 {
- return s * v.Len()
+ t := v.Type().Elem()
+ if size, ok := structSize.Load(t); ok {
+ return size.(int) * v.Len()
+ }
+
+ size := sizeof(t)
+ if size >= 0 {
+ if t.Kind() == reflect.Struct {
+ structSize.Store(t, size)
+ }
+ return size * v.Len()
}
case reflect.Struct: