mirror of
https://github.com/json-iterator/go.git
synced 2025-01-08 13:06:29 +02:00
fix reuse buffer bug
This commit is contained in:
parent
d720b761fb
commit
a460807cb4
22
jsoniter.go
22
jsoniter.go
@ -554,7 +554,27 @@ func (iter *Iterator) readObjectField() (ret string) {
|
|||||||
iter.ReportError("ReadObject", "expect : after object field")
|
iter.ReportError("ReadObject", "expect : after object field")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
iter.skipWhitespaces()
|
// skip whitespaces, and detect if buffer is rotated
|
||||||
|
for {
|
||||||
|
for i := iter.head; i < iter.tail; i++ {
|
||||||
|
c := iter.buf[i]
|
||||||
|
switch c {
|
||||||
|
case ' ', '\n', '\t', '\r':
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
iter.head = i
|
||||||
|
break
|
||||||
|
}
|
||||||
|
if iter.head == iter.tail {
|
||||||
|
// no longer safe to reuse buffer
|
||||||
|
field = string(str)
|
||||||
|
if !iter.loadMore() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
return field
|
return field
|
||||||
}
|
}
|
||||||
|
|
||||||
|
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user