types/json: replace binary.Read with binary.BigEndian.Uint16 (#23845)
This commit is contained in:
@ -137,11 +137,8 @@ func decodeEscapedUnicode(s []byte) (char [4]byte, size int, err error) {
|
||||
// The unicode must can be represented in 2 bytes.
|
||||
return char, 0, errors.Trace(err)
|
||||
}
|
||||
var unicode uint16
|
||||
err = binary.Read(bytes.NewReader(char[0:2]), binary.BigEndian, &unicode)
|
||||
if err != nil {
|
||||
return char, 0, errors.Trace(err)
|
||||
}
|
||||
|
||||
unicode := binary.BigEndian.Uint16(char[0:2])
|
||||
size = utf8.RuneLen(rune(unicode))
|
||||
utf8.EncodeRune(char[0:size], rune(unicode))
|
||||
return
|
||||
|
||||
@ -13,6 +13,8 @@
|
||||
package json
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
. "github.com/pingcap/check"
|
||||
)
|
||||
|
||||
@ -29,3 +31,10 @@ func (s *testJSONFuncSuite) TestdecodeEscapedUnicode(c *C) {
|
||||
c.Assert(err, IsNil)
|
||||
|
||||
}
|
||||
|
||||
func BenchmarkDecodeEscapedUnicode(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
in := "597d"
|
||||
decodeEscapedUnicode([]byte(in))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user