From 509a1173a33d4fd914409cd941470d440fd5eed3 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Tue, 21 May 2013 14:32:09 -0700 Subject: [PATCH] time: remove Time.FormatAppend MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit undo CL 8478044 / 0d28fd55e721 Lack of consensus. ««« original CL description time: add Time.FormatAppend This is a version of Time.Format that doesn't require allocation. Fixes #5192 Update #5195 R=r CC=gobot, golang-dev https://golang.org/cl/8478044 »»» R=r CC=golang-dev https://golang.org/cl/9462049 --- src/pkg/time/format.go | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/src/pkg/time/format.go b/src/pkg/time/format.go index e40911aa53..7fe0402312 100644 --- a/src/pkg/time/format.go +++ b/src/pkg/time/format.go @@ -380,22 +380,6 @@ func (t Time) String() string { // about the formats and the definition of the reference time, see the // documentation for ANSIC and the other constants defined by this package. func (t Time) Format(layout string) string { - const bufSize = 64 - var b []byte - max := len(layout) + 10 - if max <= bufSize { - var buf [bufSize]byte - b = buf[:0] - } else { - b = make([]byte, 0, max) - } - b = t.FormatAppend(layout, b) - return string(b) -} - -// FormatAppend works like Format but appends the textual -// representation to b and returns the extended buffer. -func (t Time) FormatAppend(layout string, b []byte) []byte { var ( name, offset, abs = t.locabs() @@ -405,7 +389,16 @@ func (t Time) FormatAppend(layout string, b []byte) []byte { hour int = -1 min int sec int + + b []byte + buf [64]byte ) + max := len(layout) + 10 + if max <= len(buf) { + b = buf[:0] + } else { + b = make([]byte, 0, max) + } // Each iteration generates one std value. for layout != "" { prefix, std, suffix := nextStdChunk(layout) @@ -553,7 +546,7 @@ func (t Time) FormatAppend(layout string, b []byte) []byte { b = formatNano(b, uint(t.Nanosecond()), std>>stdArgShift, std&stdMask == stdFracSecond9) } } - return b + return string(b) } var errBad = errors.New("bad value for field") // placeholder not passed to user -- 2.50.0