diff options
author | Ian Lance Taylor <iant@google.com> | 2014-06-04 23:15:33 +0000 |
---|---|---|
committer | Ian Lance Taylor <ian@gcc.gnu.org> | 2014-06-04 23:15:33 +0000 |
commit | bae90c989cb020d17a24919ec84c0b8dd2fae2da (patch) | |
tree | 89766166feb4ceca2d983169c5360e3f6f521b12 /libgo/go/fmt | |
parent | 82b3da6a714493644a4333bfd8205e3341ed3b8e (diff) | |
download | gcc-bae90c989cb020d17a24919ec84c0b8dd2fae2da.zip gcc-bae90c989cb020d17a24919ec84c0b8dd2fae2da.tar.gz gcc-bae90c989cb020d17a24919ec84c0b8dd2fae2da.tar.bz2 |
libgo: Merge from revision 18783:00cce3a34d7e of master library.
This revision was committed January 7, 2014. The next
revision deleted runtime/mfinal.c. That will be done in a
subsequent merge.
This merge changes type descriptors to add a zero field,
pointing to a zero value for that type. This is implemented
as a common variable.
* go-gcc.cc (Gcc_backend::implicit_variable): Add is_common and
alignment parameters. Permit init parameter to be NULL.
From-SVN: r211249
Diffstat (limited to 'libgo/go/fmt')
-rw-r--r-- | libgo/go/fmt/fmt_test.go | 2 | ||||
-rw-r--r-- | libgo/go/fmt/format.go | 5 | ||||
-rw-r--r-- | libgo/go/fmt/print.go | 40 | ||||
-rw-r--r-- | libgo/go/fmt/scan.go | 9 |
4 files changed, 16 insertions, 40 deletions
diff --git a/libgo/go/fmt/fmt_test.go b/libgo/go/fmt/fmt_test.go index bbca2c5..42b3c22 100644 --- a/libgo/go/fmt/fmt_test.go +++ b/libgo/go/fmt/fmt_test.go @@ -220,6 +220,8 @@ var fmtTests = []struct { {"%+.3e", 0.0, "+0.000e+00"}, {"%+.3e", 1.0, "+1.000e+00"}, {"%+.3f", -1.0, "-1.000"}, + {"%+07.2f", 1.0, "+001.00"}, + {"%+07.2f", -1.0, "-001.00"}, {"% .3E", -1.0, "-1.000E+00"}, {"% .3e", 1.0, " 1.000e+00"}, {"%+.3g", 0.0, "+0"}, diff --git a/libgo/go/fmt/format.go b/libgo/go/fmt/format.go index 2e2b071..a54f12e 100644 --- a/libgo/go/fmt/format.go +++ b/libgo/go/fmt/format.go @@ -372,7 +372,10 @@ func (f *fmt) formatFloat(v float64, verb byte, prec, n int) { default: // There's no sign, but we might need one. if f.plus { - slice[0] = '+' + f.buf.WriteByte('+') + f.wid-- + f.pad(slice[1:]) + return } else if f.space { // space is already there } else { diff --git a/libgo/go/fmt/print.go b/libgo/go/fmt/print.go index 1ea816d..2f13bcd 100644 --- a/libgo/go/fmt/print.go +++ b/libgo/go/fmt/print.go @@ -124,45 +124,13 @@ type pp struct { fmt fmt } -// A cache holds a set of reusable objects. -// The slice is a stack (LIFO). -// If more are needed, the cache creates them by calling new. -type cache struct { - mu sync.Mutex - saved []interface{} - new func() interface{} +var ppFree = sync.Pool{ + New: func() interface{} { return new(pp) }, } -func (c *cache) put(x interface{}) { - c.mu.Lock() - if len(c.saved) < cap(c.saved) { - c.saved = append(c.saved, x) - } - c.mu.Unlock() -} - -func (c *cache) get() interface{} { - c.mu.Lock() - n := len(c.saved) - if n == 0 { - c.mu.Unlock() - return c.new() - } - x := c.saved[n-1] - c.saved = c.saved[0 : n-1] - c.mu.Unlock() - return x -} - -func newCache(f func() interface{}) *cache { - return &cache{saved: make([]interface{}, 0, 100), new: f} -} - -var ppFree = newCache(func() interface{} { return new(pp) }) - // newPrinter allocates a new pp struct or grab a cached one. func newPrinter() *pp { - p := ppFree.get().(*pp) + p := ppFree.Get().(*pp) p.panicking = false p.erroring = false p.fmt.init(&p.buf) @@ -178,7 +146,7 @@ func (p *pp) free() { p.buf = p.buf[:0] p.arg = nil p.value = reflect.Value{} - ppFree.put(p) + ppFree.Put(p) } func (p *pp) Width() (wid int, ok bool) { return p.fmt.wid, p.fmt.widPresent } diff --git a/libgo/go/fmt/scan.go b/libgo/go/fmt/scan.go index 5b1be58..c73b8b6 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. |