1
0
mirror of https://github.com/json-iterator/go.git synced 2025-06-15 22:50:24 +02:00

use iterator from cache for any

This commit is contained in:
Tao Wen
2017-06-17 21:10:08 +08:00
parent 50e4910c63
commit 55fc498d27
8 changed files with 82 additions and 121 deletions

View File

@ -8,21 +8,12 @@ import (
type float64LazyAny struct {
baseAny
cfg *frozenConfig
buf []byte
iter *Iterator
err error
cache float64
}
func (any *float64LazyAny) Parse() *Iterator {
iter := any.iter
if iter == nil {
iter = NewIterator(ConfigDefault)
}
iter.ResetBytes(any.buf)
return iter
}
func (any *float64LazyAny) ValueType() ValueType {
return Number
}
@ -31,7 +22,8 @@ func (any *float64LazyAny) fillCache() {
if any.err != nil {
return
}
iter := any.Parse()
iter := any.cfg.BorrowIterator(any.buf)
defer any.cfg.ReturnIterator(iter)
any.cache = iter.ReadFloat64()
if iter.Error != io.EOF {
iter.reportError("floatLazyAny", "there are bytes left")