Skip to content

Commit ea64033

Browse files
committed
fix #239, empty slice
1 parent 404d907 commit ea64033

File tree

4 files changed

+22
-22
lines changed

4 files changed

+22
-22
lines changed

reflect.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
package jsoniter
22

33
import (
4-
"encoding"
5-
"encoding/json"
64
"fmt"
75
"reflect"
8-
"time"
96
"unsafe"
107
"github.com/v2pro/plz/reflect2"
118
)

reflect_slice.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ func (decoder *sliceDecoder) doDecode(ptr unsafe.Pointer, iter *Iterator) {
7878
}
7979
c = iter.nextToken()
8080
if c == ']' {
81-
sliceType.Set(ptr, sliceType.UnsafeNew())
81+
sliceType.UnsafeSet(ptr, sliceType.UnsafeMakeSlice(0, 0))
8282
return
8383
}
8484
iter.unreadByte()

type_tests/struct_test.go

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -325,27 +325,27 @@ func structFields1To11() {
325325
Field9 string
326326
})(nil),
327327
(*struct {
328-
Field1 string
329-
Field2 string
330-
Field3 string
331-
Field4 string
332-
Field5 string
333-
Field6 string
334-
Field7 string
335-
Field8 string
336-
Field9 string
328+
Field1 string
329+
Field2 string
330+
Field3 string
331+
Field4 string
332+
Field5 string
333+
Field6 string
334+
Field7 string
335+
Field8 string
336+
Field9 string
337337
Field10 string
338338
})(nil),
339339
(*struct {
340-
Field1 string
341-
Field2 string
342-
Field3 string
343-
Field4 string
344-
Field5 string
345-
Field6 string
346-
Field7 string
347-
Field8 string
348-
Field9 string
340+
Field1 string
341+
Field2 string
342+
Field3 string
343+
Field4 string
344+
Field5 string
345+
Field6 string
346+
Field7 string
347+
Field8 string
348+
Field9 string
349349
Field10 string
350350
Field11 string
351351
})(nil),

value_tests/slice_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,8 @@ func init() {
1010
unmarshalCases = append(unmarshalCases, unmarshalCase{
1111
ptr: (*[]string)(nil),
1212
input: "null",
13+
}, unmarshalCase{
14+
ptr: (*[]string)(nil),
15+
input: "[]",
1316
})
1417
}

0 commit comments

Comments
 (0)