• Daniel Martí's avatar
    encoding/json: use panics for phase errors · b2fcfc1a
    Daniel Martí authored
    Having these panic-like errors used to be ok, since they were used in
    the internal decoder state instead of passed around via return
    parameters.
    
    Recently, the decoder was rewritten to use explicit error returns
    instead. This error is a terrible fit for error returns; a handful of
    functions must return an error because of it, and their callers must
    check for an error that should never happen.
    
    This is precisely what panics are for, so use them. The test coverage of
    the package goes up from 91.3% to 91.6%, and performance is unaffected.
    We can also get rid of some unnecessary verbosity in the code.
    
    name           old time/op    new time/op    delta
    CodeDecoder-4    27.5ms ± 1%    27.5ms ± 1%   ~     (p=0.937 n=6+6)
    
    Change-Id: I01033b3f5b7c0cf0985082fa272754f96bf6353c
    Reviewed-on: https://go-review.googlesource.com/134835
    Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
    Run-TryBot: Joe Tsai <thebrokentoaster@gmail.com>
    TryBot-Result: Gobot Gobot <gobot@golang.org>
    Reviewed-by: 's avatarJoe Tsai <thebrokentoaster@gmail.com>
    b2fcfc1a
Name
Last commit
Last update
..
testdata Loading commit data...
bench_test.go Loading commit data...
decode.go Loading commit data...
decode_test.go Loading commit data...
encode.go Loading commit data...
encode_test.go Loading commit data...
example_marshaling_test.go Loading commit data...
example_test.go Loading commit data...
fold.go Loading commit data...
fold_test.go Loading commit data...
indent.go Loading commit data...
number_test.go Loading commit data...
scanner.go Loading commit data...
scanner_test.go Loading commit data...
stream.go Loading commit data...
stream_test.go Loading commit data...
tables.go Loading commit data...
tagkey_test.go Loading commit data...
tags.go Loading commit data...
tags_test.go Loading commit data...