diff --git a/jsoniter.go b/jsoniter.go index a47e551..2d038f6 100644 --- a/jsoniter.go +++ b/jsoniter.go @@ -70,6 +70,9 @@ func (iter *Iterator) skipWhitespaces() { } func (iter *Iterator) ReportError(operation string, msg string) { + if iter.Error != nil { + return + } peekStart := iter.head - 10 if peekStart < 0 { peekStart = 0 @@ -591,25 +594,16 @@ func (iter *Iterator) ReadBool() (ret bool) { func (iter *Iterator) skipTrue() { c := iter.readByte() - if iter.Error != nil { - return - } if c != 'r' { iter.ReportError("skipTrue", "expect r of true") return } c = iter.readByte() - if iter.Error != nil { - return - } if c != 'u' { iter.ReportError("skipTrue", "expect u of true") return } c = iter.readByte() - if iter.Error != nil { - return - } if c != 'e' { iter.ReportError("skipTrue", "expect e of true") return @@ -618,33 +612,21 @@ func (iter *Iterator) skipTrue() { func (iter *Iterator) skipFalse() { c := iter.readByte() - if iter.Error != nil { - return - } if c != 'a' { iter.ReportError("skipFalse", "expect a of false") return } c = iter.readByte() - if iter.Error != nil { - return - } if c != 'l' { iter.ReportError("skipFalse", "expect l of false") return } c = iter.readByte() - if iter.Error != nil { - return - } if c != 's' { iter.ReportError("skipFalse", "expect s of false") return } c = iter.readByte() - if iter.Error != nil { - return - } if c != 'e' { iter.ReportError("skipFalse", "expect e of false") return @@ -653,14 +635,8 @@ func (iter *Iterator) skipFalse() { func (iter *Iterator) ReadNull() (ret bool) { c := iter.readByte() - if iter.Error != nil { - return - } if c == 'n' { iter.skipNull() - if iter.Error != nil { - return - } return true } iter.unreadByte() @@ -669,25 +645,16 @@ func (iter *Iterator) ReadNull() (ret bool) { func (iter *Iterator) skipNull() { c := iter.readByte() - if iter.Error != nil { - return - } if c != 'u' { iter.ReportError("skipNull", "expect u of null") return } c = iter.readByte() - if iter.Error != nil { - return - } if c != 'l' { iter.ReportError("skipNull", "expect l of null") return } c = iter.readByte() - if iter.Error != nil { - return - } if c != 'l' { iter.ReportError("skipNull", "expect l of null") return @@ -727,9 +694,6 @@ func (iter *Iterator) skipString() { return // end of string found case '\\': iter.readByte() // " after \\ does not count - if iter.Error != nil { - return - } } } } @@ -760,9 +724,6 @@ func (iter *Iterator) skipArray() { iter.Skip() iter.skipWhitespaces() c = iter.readByte() - if iter.Error != nil { - return - } switch c { case ',': iter.skipWhitespaces() @@ -790,9 +751,6 @@ func (iter *Iterator) skipObject() { for { iter.skipWhitespaces() c := iter.readByte() - if iter.Error != nil { - return - } if c != '"' { iter.ReportError("skipObject", `expects "`) return @@ -800,9 +758,6 @@ func (iter *Iterator) skipObject() { iter.skipString() iter.skipWhitespaces() c = iter.readByte() - if iter.Error != nil { - return - } if c != ':' { iter.ReportError("skipObject", `expects :`) return @@ -811,9 +766,6 @@ func (iter *Iterator) skipObject() { iter.Skip() iter.skipWhitespaces() c = iter.readByte() - if iter.Error != nil { - return - } switch c { case ',': iter.skipWhitespaces() diff --git a/jsoniter_reflect.go b/jsoniter_reflect.go index 2ca0b52..c13ffa1 100644 --- a/jsoniter_reflect.go +++ b/jsoniter_reflect.go @@ -118,9 +118,6 @@ type stringNumberDecoder struct { func (decoder *stringNumberDecoder) decode(ptr unsafe.Pointer, iter *Iterator) { c := iter.readByte() - if iter.Error != nil { - return - } if c != '"' { iter.ReportError("stringNumberDecoder", `expect "`) return @@ -130,9 +127,6 @@ func (decoder *stringNumberDecoder) decode(ptr unsafe.Pointer, iter *Iterator) { return } c = iter.readByte() - if iter.Error != nil { - return - } if c != '"' { iter.ReportError("stringNumberDecoder", `expect "`) return @@ -160,7 +154,7 @@ type structDecoder struct { } func (decoder *structDecoder) decode(ptr unsafe.Pointer, iter *Iterator) { - for field := iter.ReadObject(); field != "" && iter.Error == nil; field = iter.ReadObject() { + for field := iter.ReadObject(); field != ""; field = iter.ReadObject() { fieldDecoder := decoder.fields[field] if fieldDecoder == nil { iter.Skip() @@ -202,7 +196,7 @@ type sliceHeader struct { func (decoder *sliceDecoder) decode(ptr unsafe.Pointer, iter *Iterator) { slice := (*sliceHeader)(ptr) slice.Len = 0 - for iter.ReadArray() && iter.Error == nil { + for iter.ReadArray() { offset := uintptr(slice.Len) * decoder.elemType.Size() growOne(slice, decoder.sliceType, decoder.elemType) dataPtr := uintptr(slice.Data) + offset