forked from mirror/go-json
revert initialize elem pointer & remove unnecessary benchmark
This commit is contained in:
parent
f8aac1e69f
commit
a52bba9099
|
@ -127,7 +127,7 @@ func (d *sliceDecoder) decodeStream(s *stream, depth int64, p unsafe.Pointer) er
|
|||
// assign new element to the slice
|
||||
typedmemmove(d.elemType, ep, unsafe_New(d.elemType))
|
||||
} else if d.isElemPointerType {
|
||||
*(*unsafe.Pointer)(ep) = nil // initialize elem pointer
|
||||
**(**unsafe.Pointer)(unsafe.Pointer(&ep)) = nil // initialize elem pointer
|
||||
}
|
||||
if err := d.valueDecoder.decodeStream(s, depth, ep); err != nil {
|
||||
return err
|
||||
|
@ -240,7 +240,7 @@ func (d *sliceDecoder) decode(buf []byte, cursor, depth int64, p unsafe.Pointer)
|
|||
// assign new element to the slice
|
||||
typedmemmove(d.elemType, ep, unsafe_New(d.elemType))
|
||||
} else if d.isElemPointerType {
|
||||
*(*unsafe.Pointer)(ep) = nil // initialize elem pointer
|
||||
**(**unsafe.Pointer)(unsafe.Pointer(&ep)) = nil // initialize elem pointer
|
||||
}
|
||||
c, err := d.valueDecoder.decode(buf, cursor, depth, ep)
|
||||
if err != nil {
|
||||
|
|
|
@ -3508,46 +3508,3 @@ func TestDecodeBackSlash(t *testing.T) {
|
|||
})
|
||||
})
|
||||
}
|
||||
|
||||
var (
|
||||
isWhiteSpace = [256]bool{}
|
||||
)
|
||||
|
||||
func init() {
|
||||
isWhiteSpace[' '] = true
|
||||
isWhiteSpace['\n'] = true
|
||||
isWhiteSpace['\t'] = true
|
||||
isWhiteSpace['\r'] = true
|
||||
}
|
||||
|
||||
func skipWhiteSpace(buf []byte, cursor int64) int64 {
|
||||
LOOP:
|
||||
if isWhiteSpace[buf[cursor]] {
|
||||
cursor++
|
||||
goto LOOP
|
||||
}
|
||||
return cursor
|
||||
}
|
||||
|
||||
func skipWhiteSpaceLoop(buf []byte, cursor int64) int64 {
|
||||
for isWhiteSpace[buf[cursor]] {
|
||||
cursor++
|
||||
}
|
||||
return cursor
|
||||
}
|
||||
|
||||
func BenchmarkSkipWhiteSpace(b *testing.B) {
|
||||
data := []byte(" \n\r\t \n\r\t \n\r\t \n\r\t \n\r\t \n\r\t \n\r\t \n\r\t \n\r\t \n\r\t \n\r\t \n\r\t \n\r\t \n\r\t \n\r\t \n\r\t \n\r\t \n\r\t \n\r\t \n\r\t \n\r\t \n\r\t \n\r\t}")
|
||||
b.ReportAllocs()
|
||||
b.ResetTimer()
|
||||
b.Run("gotoLabel", func(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
skipWhiteSpace(data, 0)
|
||||
}
|
||||
})
|
||||
b.Run("loop", func(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
skipWhiteSpaceLoop(data, 0)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue