Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(30)

Delta Between Two Patch Sets: src/pkg/time/format.go

Issue 5992058: code review 5992058: time: in Format give buffer an initial capacity
Left Patch Set: Created 11 years, 11 months ago
Right Patch Set: diff -r d685ccae1668 https://go.googlecode.com/hg/ Created 11 years, 11 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
(no file at all)
1 // Copyright 2010 The Go Authors. All rights reserved. 1 // Copyright 2010 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style 2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file. 3 // license that can be found in the LICENSE file.
4 4
5 package time 5 package time
6 6
7 import "errors" 7 import "errors"
8 8
9 // These are predefined layouts for use in Time.Format. 9 // These are predefined layouts for use in Time.Format.
10 // The standard time used in the layouts is: 10 // The standard time used in the layouts is:
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after
360 // representations. For more information about the formats and the 360 // representations. For more information about the formats and the
361 // definition of the standard time, see the documentation for ANSIC. 361 // definition of the standard time, see the documentation for ANSIC.
362 func (t Time) Format(layout string) string { 362 func (t Time) Format(layout string) string {
363 var ( 363 var (
364 year int = -1 364 year int = -1
365 month Month 365 month Month
366 day int 366 day int
367 hour int = -1 367 hour int = -1
368 min int 368 min int
369 sec int 369 sec int
370 » » b buffer 370 » » b buffer = make([]byte, 0, len(layout))
371 ) 371 )
372 // Each iteration generates one std value. 372 // Each iteration generates one std value.
373 for { 373 for {
374 prefix, std, suffix := nextStdChunk(layout) 374 prefix, std, suffix := nextStdChunk(layout)
375 b.WriteString(prefix) 375 b.WriteString(prefix)
376 if std == "" { 376 if std == "" {
377 break 377 break
378 } 378 }
379 379
380 // Compute year, month, day if needed. 380 // Compute year, month, day if needed.
(...skipping 648 matching lines...) Expand 10 before | Expand all | Expand 10 after
1029 } 1029 }
1030 1030
1031 f += g * unit 1031 f += g * unit
1032 } 1032 }
1033 1033
1034 if neg { 1034 if neg {
1035 f = -f 1035 f = -f
1036 } 1036 }
1037 return Duration(f), nil 1037 return Duration(f), nil
1038 } 1038 }
LEFTRIGHT
« no previous file | no next file » | Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Toggle Comments ('s')

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b