From f8447327036119b499eee922e8e8c149ac2c85e6 Mon Sep 17 00:00:00 2001 From: smallhowcao Date: Thu, 21 Sep 2023 11:10:18 +0800 Subject: [PATCH 1/4] process bytes more efficiently --- mapstructure.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/mapstructure.go b/mapstructure.go index 7581806a..69aeaf0d 100644 --- a/mapstructure.go +++ b/mapstructure.go @@ -1126,6 +1126,12 @@ func (d *Decoder) decodeSlice(name string, data interface{}, val reflect.Value) } else if valSlice.Len() > dataVal.Len() { valSlice = valSlice.Slice(0, dataVal.Len()) } + + if bytesData, ok := data.([]byte); ok { + bytesVal := reflect.Indirect(reflect.ValueOf(bytesData)) + val.Set(bytesVal) + return nil + } // Accumulate any errors errors := make([]string, 0) From c5f4c37ceb865658580562adf2aae068b2171a35 Mon Sep 17 00:00:00 2001 From: smallhowcao Date: Thu, 21 Sep 2023 14:55:19 +0800 Subject: [PATCH 2/4] process bytes more efficiently --- mapstructure.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/mapstructure.go b/mapstructure.go index 69aeaf0d..3c892b17 100644 --- a/mapstructure.go +++ b/mapstructure.go @@ -1126,10 +1126,12 @@ func (d *Decoder) decodeSlice(name string, data interface{}, val reflect.Value) } else if valSlice.Len() > dataVal.Len() { valSlice = valSlice.Slice(0, dataVal.Len()) } - + if bytesData, ok := data.([]byte); ok { - bytesVal := reflect.Indirect(reflect.ValueOf(bytesData)) - val.Set(bytesVal) + if valElemType.Kind() == reflect.Uint8 { + bytesVal := reflect.Indirect(reflect.ValueOf(bytesData)) + val.Set(bytesVal) + } return nil } From e8e2b95f28ef8b72baa83252a5a3f29a925293bb Mon Sep 17 00:00:00 2001 From: smallhowcao Date: Thu, 21 Sep 2023 15:00:05 +0800 Subject: [PATCH 3/4] process bytes more efficiently --- mapstructure.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mapstructure.go b/mapstructure.go index 3c892b17..0a3bcf67 100644 --- a/mapstructure.go +++ b/mapstructure.go @@ -1131,8 +1131,8 @@ func (d *Decoder) decodeSlice(name string, data interface{}, val reflect.Value) if valElemType.Kind() == reflect.Uint8 { bytesVal := reflect.Indirect(reflect.ValueOf(bytesData)) val.Set(bytesVal) + return nil } - return nil } // Accumulate any errors From 75ea41c534d4f7e254337237927acafd2f68cfed Mon Sep 17 00:00:00 2001 From: smallhowcao Date: Thu, 21 Sep 2023 15:01:00 +0800 Subject: [PATCH 4/4] process bytes more efficiently --- mapstructure.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/mapstructure.go b/mapstructure.go index 0a3bcf67..a1b0c0f4 100644 --- a/mapstructure.go +++ b/mapstructure.go @@ -1129,8 +1129,7 @@ func (d *Decoder) decodeSlice(name string, data interface{}, val reflect.Value) if bytesData, ok := data.([]byte); ok { if valElemType.Kind() == reflect.Uint8 { - bytesVal := reflect.Indirect(reflect.ValueOf(bytesData)) - val.Set(bytesVal) + val.Set(reflect.Indirect(reflect.ValueOf(bytesData))) return nil } }