diff options
Diffstat (limited to 'libgo/go/encoding/json/stream.go')
-rw-r--r-- | libgo/go/encoding/json/stream.go | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/libgo/go/encoding/json/stream.go b/libgo/go/encoding/json/stream.go index 7d5137f..e291274 100644 --- a/libgo/go/encoding/json/stream.go +++ b/libgo/go/encoding/json/stream.go @@ -92,20 +92,23 @@ func (dec *Decoder) readValue() (int, error) { scanp := dec.scanp var err error Input: - for { + // help the compiler see that scanp is never negative, so it can remove + // some bounds checks below. + for scanp >= 0 { + // Look in the buffer for a new value. - for i, c := range dec.buf[scanp:] { + for ; scanp < len(dec.buf); scanp++ { + c := dec.buf[scanp] dec.scan.bytes++ switch dec.scan.step(&dec.scan, c) { case scanEnd: - scanp += i break Input case scanEndObject, scanEndArray: // scanEnd is delayed one byte. // We might block trying to get that byte from src, // so instead invent a space byte. if stateEndValue(&dec.scan, ' ') == scanEnd { - scanp += i + 1 + scanp++ break Input } case scanError: @@ -113,7 +116,6 @@ Input: return 0, dec.scan.err } } - scanp = len(dec.buf) // Did the last read have an error? // Delayed until now to allow buffer scan. |