From ea6403326b91fca8e743bc95a5be5eacedd55417 Mon Sep 17 00:00:00 2001 From: Tao Wen Date: Wed, 21 Feb 2018 07:24:22 +0800 Subject: [PATCH] fix #239, empty slice --- reflect.go | 3 --- reflect_slice.go | 2 +- type_tests/struct_test.go | 36 ++++++++++++++++++------------------ value_tests/slice_test.go | 3 +++ 4 files changed, 22 insertions(+), 22 deletions(-) diff --git a/reflect.go b/reflect.go index 511a776..1cdb954 100644 --- a/reflect.go +++ b/reflect.go @@ -1,11 +1,8 @@ package jsoniter import ( - "encoding" - "encoding/json" "fmt" "reflect" - "time" "unsafe" "github.com/v2pro/plz/reflect2" ) diff --git a/reflect_slice.go b/reflect_slice.go index 5d66238..92a97b8 100644 --- a/reflect_slice.go +++ b/reflect_slice.go @@ -78,7 +78,7 @@ func (decoder *sliceDecoder) doDecode(ptr unsafe.Pointer, iter *Iterator) { } c = iter.nextToken() if c == ']' { - sliceType.Set(ptr, sliceType.UnsafeNew()) + sliceType.UnsafeSet(ptr, sliceType.UnsafeMakeSlice(0, 0)) return } iter.unreadByte() diff --git a/type_tests/struct_test.go b/type_tests/struct_test.go index 25162fe..0cf3252 100644 --- a/type_tests/struct_test.go +++ b/type_tests/struct_test.go @@ -325,27 +325,27 @@ func structFields1To11() { Field9 string })(nil), (*struct { - Field1 string - Field2 string - Field3 string - Field4 string - Field5 string - Field6 string - Field7 string - Field8 string - Field9 string + Field1 string + Field2 string + Field3 string + Field4 string + Field5 string + Field6 string + Field7 string + Field8 string + Field9 string Field10 string })(nil), (*struct { - Field1 string - Field2 string - Field3 string - Field4 string - Field5 string - Field6 string - Field7 string - Field8 string - Field9 string + Field1 string + Field2 string + Field3 string + Field4 string + Field5 string + Field6 string + Field7 string + Field8 string + Field9 string Field10 string Field11 string })(nil), diff --git a/value_tests/slice_test.go b/value_tests/slice_test.go index 17722c0..f14823f 100644 --- a/value_tests/slice_test.go +++ b/value_tests/slice_test.go @@ -10,5 +10,8 @@ func init() { unmarshalCases = append(unmarshalCases, unmarshalCase{ ptr: (*[]string)(nil), input: "null", + }, unmarshalCase{ + ptr: (*[]string)(nil), + input: "[]", }) }