1
0
mirror of https://github.com/golang/go synced 2024-10-04 14:31:21 -06:00
Commit Graph

238 Commits

Author SHA1 Message Date
Dmitriy Vyukov
44cc8e5cc9 fmt: use RunParallel in benchmarks
LGTM=bradfitz
R=golang-codereviews, bradfitz
CC=golang-codereviews
https://golang.org/cl/67910046
2014-02-24 20:46:25 +04:00
Marcel van Lohuizen
746d636859 unicode: upgrade to Unicode 6.3.0
This is a relatively minor change.

This does not result in changes to go.text/unicode/norm. The go.text
packages will therefore be relatively unaffected. It does make the
way for an upgrade to CLDR 24, though.

The tests of all.bash pass, as well as the tests in go.text after
this update.

LGTM=r
R=r
CC=golang-codereviews
https://golang.org/cl/65400044
2014-02-18 20:12:59 +01:00
Rob Pike
fc908a0298 fmt: fix bug printing large zero-padded hexadecimal
We forgot to include the width of "0x" when computing the crossover
from internal buffer to allocated buffer.
Also add a helper function to the test for formatting large zero-padded
test strings.

Fixes #6777.

R=golang-codereviews, iant
CC=golang-codereviews
https://golang.org/cl/50820043
2014-01-16 09:48:23 -08:00
Dmitriy Vyukov
7f62d08777 fmt: make benchmarks parallel
This seems to be the best target to benchmark sync.Pool changes.

This is resend of cl/49910043 which was LGTMed by
TBR=bradfitz

R=golang-codereviews
CC=golang-codereviews
https://golang.org/cl/50140045
2014-01-10 13:51:11 +04:00
Brad Fitzpatrick
0f9311811c fmt: use sync.Pool
Update #4720

R=golang-dev, iant
CC=golang-dev
https://golang.org/cl/43990043
2013-12-18 11:09:07 -08:00
Felix Geisendörfer
5ad5b7a551 fmt: Fix signed zero-padding for positive floats
Space padding still has the same issue, I will send a separate patch for that
if this one gets accepted.
Fixes #6856.

R=golang-dev, r
CC=golang-dev
https://golang.org/cl/35660043
2013-12-12 06:40:16 -08:00
Rob Pike
3e3ed5d978 fmt: one bad index shouldn't spoil them all
In an indexed verb such as %[3]d, if the index is out of range, don't
skip processing the rest of the verbs. The bug was that the bad
index set a bit for the whole format instead of just the verb.

Ok for 1.2 because this is a bug in a 1.2 feature.

Fixes #6434

R=golang-dev, adg
CC=golang-dev
https://golang.org/cl/13632058
2013-09-23 16:03:57 +10:00
Rob Pike
89dacb9cca fmt: %b for complex64 and complex128
Just an oversight they were missing.
Fixes #6387

R=golang-dev, dominik.honnef, rsc
CC=golang-dev
https://golang.org/cl/13715043
2013-09-15 10:45:36 +10:00
Robin Eklind
cfb02f7b74 fmt: Remove some unnecessary conversions.
R=golang-dev, remyoudompheng
CC=golang-dev
https://golang.org/cl/12795052
2013-08-28 11:55:39 -07:00
Rob Pike
f578726de1 all: protect alloc count tests by -testing.short
Update #5000
Should reduce the flakiness a little. Malloc counting is important
to general testing but not to the build dashboard, which uses -short.

R=golang-dev, dsymonds
CC=golang-dev
https://golang.org/cl/12866047
2013-08-21 14:00:45 +10:00
Rob Pike
f59064de80 fmt: fix up zero padding
If the padding is huge, we crashed by blowing the buffer. That's easy: make sure
we have a big enough buffer by allocating in problematic cases.
Zero padding floats was just wrong in general: the space would appear in the
middle.

Fixes #6044.

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/12498043
2013-08-07 08:38:46 +10:00
Rob Pike
fba7b04dcb fmt: clean up some errors found by vet
Includes deleting some unused items.

R=golang-dev, adg
CC=golang-dev
https://golang.org/cl/12305043
2013-08-02 11:38:19 +10:00
Robert Daniel Kortschak
53b61057b2 fmt: make all errors begin with the string "%!", always.
Fixes #5730.

R=dsymonds, r, kamil.kisiel
CC=golang-dev
https://golang.org/cl/11998044
2013-07-31 16:11:12 +10:00
Rob Pike
221af5c12f fmt: treat \r\n as \n in Scan
When scanning input and "white space" is permitted, a carriage return
followed immediately by a newline (\r\n) is treated exactly the same
as a plain newline (\n). I hope this makes it work better on Windows.

We do it everywhere, not just on Windows, since why not?

Fixes #5391.

R=golang-dev, dsymonds
CC=golang-dev
https://golang.org/cl/12142043
2013-07-31 15:00:08 +10:00
Rob Pike
609d742e79 fmt: remove "Scan:" prefix from error messages
The prefix was not uniformly applied and is probably better left off anyway.

Fixes #4944.

R=golang-dev, dsymonds
CC=golang-dev
https://golang.org/cl/12140043
2013-07-31 14:09:19 +10:00
Rob Pike
02ad82fe15 fmt: put a ! in all error output generated by Printf-like functions
Fixes #5730.

R=golang-dev, dsymonds
CC=golang-dev
https://golang.org/cl/12141043
2013-07-31 14:08:47 +10:00
Rob Pike
abe384f68a all: be more idiomatic when documenting boolean return values.
Phrases like "returns whether or not the image is opaque" could be
describing what the function does (it always returns, regardless of
the opacity) or what it returns (a boolean indicating the opacity).
Even when the "or not" is missing, the phrasing is bizarre.

Go with "reports whether", which is still clunky but at least makes
it clear we're talking about the return value.

These were edited by hand. A few were cleaned up in other ways.

R=golang-dev, dsymonds
CC=golang-dev
https://golang.org/cl/11699043
2013-07-23 11:59:49 +10:00
Rob Pike
0bc7e79afd all: excise some warts found by vet -shadow
These are not erroneous, just poor or confusing.

R=golang-dev, bradfitz
CC=golang-dev
https://golang.org/cl/10448043
2013-06-20 16:14:40 -07:00
Rob Pike
d84132cce7 fmt: change evalutation of indexed arg to match docs
The old code put the index before the period in the precision;
it should be after so it's always before the star, as documented.
A little trickier to do in one pass but compensated for by more
tests and catching a couple of other error cases.

R=rsc
CC=golang-dev
https://golang.org/cl/9751044
2013-05-29 11:29:29 -04:00
Rob Pike
7472ce0e58 fmt.Printf: introduce notation for random access to arguments.
This text is added to doc.go:

        Explicit argument indexes:

        In Printf, Sprintf, and Fprintf, the default behavior is for each
        formatting verb to format successive arguments passed in the call.
        However, the notation [n] immediately before the verb indicates that the
        nth one-indexed argument is to be formatted instead. The same notation
        before a '*' for a width or precision selects the argument index holding
        the value. After processing a bracketed expression [n], arguments n+1,
        n+2, etc. will be processed unless otherwise directed.

        For example,
                fmt.Sprintf("%[2]d %[1]d\n", 11, 22)
        will yield "22, 11", while
                fmt.Sprintf("%[3]*[2].*[1]f", 12.0, 2, 6),
        equivalent to
                fmt.Sprintf("%6.2f", 12.0),
        will yield " 12.00". Because an explicit index affects subsequent verbs,
        this notation can be used to print the same values multiple times
        by resetting the index for the first argument to be repeated:
                fmt.Sprintf("%d %d %#[1]x %#x", 16, 17)
        will yield "16 17 0x10 0x11".

The notation chosen differs from that in C, but I believe it's easier to read
and to remember (we're indexing the arguments), and compatibility with
C's printf was never a strong goal anyway.

While we're here, change the word "field" to "arg" or "argument" in the
code; it was being misused and was confusing.

R=rsc, bradfitz, rogpeppe, minux.ma, peter.armitage
CC=golang-dev
https://golang.org/cl/9680043
2013-05-24 15:49:26 -07:00
Rob Pike
b42c8294eb fmt: fix crash for Printf("%.", 3)
Fixes #5311

R=golang-dev, bradfitz, iant
CC=golang-dev
https://golang.org/cl/8961050
2013-04-29 13:52:07 -07:00
Ian Lance Taylor
806dea82d4 fmt: document that if String or Error panics, that value is printed
Fixes #5350.

R=r, minux.ma
CC=golang-dev
https://golang.org/cl/8950043
2013-04-29 12:01:32 -07:00
Rob Pike
bb195f6793 fmt: tweak the explanation of Stringer to be more correct and less specific
The String method is called whenever the printing operation wants a string,
not just for %s and %v.

R=golang-dev, bradfitz
CC=golang-dev
https://golang.org/cl/8638043
2013-04-10 14:05:34 -07:00
Albert Strasheim
0a71a5b029 all: Skip AllocsPerRun tests if GOMAXPROCS>1.
Fixes #4974.

R=rsc, bradfitz, r
CC=golang-dev
https://golang.org/cl/7545043
2013-03-06 15:52:32 -08:00
Shenghou Ma
4692711d7f strconv, fmt: clarify behavior of CanBackquote and "%#q".
Fixes #4858.

R=golang-dev, bradfitz, r, rsc
CC=golang-dev
https://golang.org/cl/7387044
2013-02-26 06:33:59 +08:00
Robert Dinu
cbd2c7a283 fmt: fix width for nil values
Apply width when using Printf with nil values.
Fixes #4772.

R=r, adg
CC=golang-dev
https://golang.org/cl/7314114
2013-02-20 14:30:15 -08:00
Kyle Lemons
9bfd3c3937 testing: add AllocsPerRun
This CL also replaces similar loops in other stdlib
package tests with calls to AllocsPerRun.

Fixes #4461.

R=minux.ma, rsc
CC=golang-dev
https://golang.org/cl/7002055
2013-02-02 22:52:29 -05:00
Robert Daniel Kortschak
92bc896909 fmt: improve go syntax handling of byte-derived arrays and slices
Fixes #4685.

R=golang-dev, adg, remyoudompheng, rsc
CC=golang-dev
https://golang.org/cl/7205047
2013-01-30 17:53:53 -08:00
Robin Eklind
3692dfdd0a fmt: Remove dead code and make comments and variables consistent.
R=minux.ma, dave, rsc
CC=golang-dev
https://golang.org/cl/7064055
2013-01-22 17:12:45 -05:00
Oling Cat
f296adf819 fmt: update an old comment; fix a typo.
R=golang-dev, iant
CC=golang-dev, minux.ma
https://golang.org/cl/6998055
2012-12-25 14:54:24 -08:00
Russ Cox
1cad1f8d1c fmt: document width and flags a bit more
Fixes #4581.

R=golang-dev, bradfitz
CC=golang-dev
https://golang.org/cl/7000052
2012-12-22 13:36:39 -05:00
Shenghou Ma
5a2c275be1 fmt, encoding/gob: fix misuse of Read
reader.Read() can return both 0,nil and len(buf),err.
To be safe, we use io.ReadFull instead of doing reader.Read directly.

Fixes #3472.

R=bradfitz, rsc, ality
CC=golang-dev
https://golang.org/cl/6285050
2012-12-18 01:26:48 +08:00
Oling Cat
6dd7da8566 fmt: fix a typo
R=golang-dev, dsymonds
CC=golang-dev
https://golang.org/cl/6937065
2012-12-17 18:13:12 +11:00
Russ Cox
07cc05864c fmt: fix %v of complex slice
Fixes #4525.

R=golang-dev, bradfitz
CC=golang-dev
https://golang.org/cl/6929049
2012-12-11 11:49:41 -05:00
Shenghou Ma
9e30b708a1 all: set GOMAXPROCS to 1 when counting mallocs
also fix an annoying test that relies on $GOROOT be set.
Fixes #3690.

R=golang-dev, bradfitz
CC=golang-dev
https://golang.org/cl/6844086
2012-12-01 00:38:01 +08:00
Robert Griesemer
465b9c35e5 gofmt: apply gofmt -w src misc
Remove trailing whitespace in comments.
No other changes.

R=r
CC=golang-dev
https://golang.org/cl/6815053
2012-10-30 13:38:01 -07:00
Rob Pike
e171b97ee6 fmt: document some undocumented details
Better explanation of width for floating-point values.
Explain that scanning does not handle %#q etc.

Fixes #4202.
Fixes #4206.

R=golang-dev, adg, rsc, iant
CC=golang-dev
https://golang.org/cl/6620074
2012-10-12 16:16:55 +11:00
Rob Pike
ffea835b8f fmt: allow # and x together for strings
Silly and small but easy to be consistent.
To make it worthwhile, I eliminated an allocation when using
%x on a byte slice.

Fixes #4149.

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/6574046
2012-09-27 06:21:38 +10:00
Rob Pike
3ba0f6daf5 fmt: honor integer radix formats (%d etc.) for pointers
Before, pointers always appeared as 0x1234ABCD. This CL
keeps that as the default for %p and %v, but lets explicit
numeric verbs override the default.
Fixes #3936.

R=golang-dev, iant
CC=golang-dev
https://golang.org/cl/6441152
2012-08-17 16:12:25 -07:00
Rob Pike
a308be5fa8 fmt: set p.field before nil check
Fixes #3752.

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/6331062
2012-06-25 16:48:20 -07:00
Rob Pike
2a0fdf6ea0 fmt.Fscanf: don't read past newline
Makes interactive uses work line-by-line.
Fixes #3481.

R=golang-dev, bradfitz, r
CC=golang-dev
https://golang.org/cl/6297075
2012-06-11 17:52:09 -04:00
Daniel Morsing
c8cbbd31f0 fmt: fix doc typo
R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/6308046
2012-06-06 16:54:02 -04:00
Russ Cox
ee3c272611 fmt: fix inadvertent change to %#v
The reordering speedup in CL 6245068 changed the semantics
of %#v by delaying the clearing of some flags.  Restore the old
semantics and add a test.

Fixes #3706.

R=golang-dev, r
CC=golang-dev
https://golang.org/cl/6302048
2012-06-06 15:08:00 -04:00
Rob Pike
53bc19442d fmt: speed up 10-20%
The check for Stringer etc. can only fire if the test is not a builtin, so avoid
the expensive check if we know there's no chance.
Also put in a fast path for pad, which saves a more modest amount.

benchmark                      old ns/op    new ns/op    delta
BenchmarkSprintfEmpty                148          152   +2.70%
BenchmarkSprintfString               585          497  -15.04%
BenchmarkSprintfInt                  441          396  -10.20%
BenchmarkSprintfIntInt               718          603  -16.02%
BenchmarkSprintfPrefixedInt          676          621   -8.14%
BenchmarkSprintfFloat               1003          953   -4.99%
BenchmarkManyArgs                   2945         2312  -21.49%
BenchmarkScanInts                1704152      1734441   +1.78%
BenchmarkScanRecursiveInt        1837397      1828920   -0.46%

R=golang-dev, bradfitz
CC=golang-dev
https://golang.org/cl/6245068
2012-05-29 15:08:08 -07:00
Rob Pike
a662d3d9a7 fmt: fix crash of %b on huge negative int64
The buffer had 64 bytes but needs one more for the sign.

Fixes #3510.

R=golang-dev, dave, dsymonds
CC=golang-dev
https://golang.org/cl/6011057
2012-04-13 09:28:37 +10:00
Shenghou Ma
62bb39e2ba fmt: remove dead code
Also fix a typo in comment.

R=golang-dev, r, r
CC=golang-dev
https://golang.org/cl/5808043
2012-03-14 04:59:17 +08:00
Robert Hencke
663a7716a1 crypto/tls, fmt: print fixes
R=golang-dev, bradfitz, minux.ma, rsc, bradfitz
CC=golang-dev
https://golang.org/cl/5787069
2012-03-12 12:04:45 +09:00
Volker Dobler
d7d1b18a5d fmt: minor tweak of package doc to show headings in godoc
R=golang-dev, adg
CC=golang-dev
https://golang.org/cl/5781052
2012-03-08 22:22:36 +11:00
Russ Cox
0bc18811b5 fmt, log: stop using unicode
$ go list -f '{{.ImportPath}} {{.Deps}}' fmt log
fmt [errors io math os reflect runtime strconv sync sync/atomic syscall time unicode/utf8 unsafe]
log [errors fmt io math os reflect runtime strconv sync sync/atomic syscall time unicode/utf8 unsafe]

R=bradfitz, rogpeppe, r, r, rsc
CC=golang-dev
https://golang.org/cl/5753055
2012-03-06 23:27:11 -05:00
Rob Pike
c0e74b63cf fmt: scan FALSE correctly
Fixes bug 2922.

R=golang-dev, bradfitz
CC=golang-dev
https://golang.org/cl/5642072
2012-02-09 14:12:55 +11:00