diff options
Diffstat (limited to 'libgo/go/fmt/scan.go')
-rw-r--r-- | libgo/go/fmt/scan.go | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/libgo/go/fmt/scan.go b/libgo/go/fmt/scan.go index 5b1be5891b8..c73b8b60283 100644 --- a/libgo/go/fmt/scan.go +++ b/libgo/go/fmt/scan.go @@ -11,6 +11,7 @@ import ( "os" "reflect" "strconv" + "sync" "unicode/utf8" ) @@ -380,7 +381,9 @@ func (r *readRune) ReadRune() (rr rune, size int, err error) { return } -var ssFree = newCache(func() interface{} { return new(ss) }) +var ssFree = sync.Pool{ + New: func() interface{} { return new(ss) }, +} // newScanState allocates a new ss struct or grab a cached one. func newScanState(r io.Reader, nlIsSpace, nlIsEnd bool) (s *ss, old ssave) { @@ -395,7 +398,7 @@ func newScanState(r io.Reader, nlIsSpace, nlIsEnd bool) (s *ss, old ssave) { return } - s = ssFree.get().(*ss) + s = ssFree.Get().(*ss) if rr, ok := r.(io.RuneReader); ok { s.rr = rr } else { @@ -427,7 +430,7 @@ func (s *ss) free(old ssave) { } s.buf = s.buf[:0] s.rr = nil - ssFree.put(s) + ssFree.Put(s) } // skipSpace skips spaces and maybe newlines. |