mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
encoding/json: add test for Unmarshal of malformed data
Roll back CL making primitive type unmarshal faster, because it broke the Unmarshal of malformed data. Add benchmarks for unmarshal of primitive types. Update #3949. R=golang-dev, bradfitz CC=golang-dev https://golang.org/cl/7228061
This commit is contained in:
parent
ec1948a44d
commit
ad37081b67
3 changed files with 55 additions and 21 deletions
|
|
@ -52,25 +52,6 @@ import (
|
|||
// an UnmarshalTypeError describing the earliest such error.
|
||||
//
|
||||
func Unmarshal(data []byte, v interface{}) error {
|
||||
|
||||
// skip heavy processing for primitive values
|
||||
var first byte
|
||||
var i int
|
||||
for i, first = range data {
|
||||
if !isSpace(rune(first)) {
|
||||
break
|
||||
}
|
||||
}
|
||||
if first != '{' && first != '[' {
|
||||
rv := reflect.ValueOf(v)
|
||||
if rv.Kind() != reflect.Ptr || rv.IsNil() {
|
||||
return &InvalidUnmarshalError{reflect.TypeOf(v)}
|
||||
}
|
||||
var d decodeState
|
||||
d.literalStore(data[i:], rv.Elem(), false)
|
||||
return d.savedError
|
||||
}
|
||||
|
||||
d := new(decodeState).init(data)
|
||||
|
||||
// Quick check for well-formedness.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue