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

174 Commits

Author SHA1 Message Date
Rob Pike
66410bac3d fmt: benchmark floating point.
mallocs per Sprintf("%x"): 1
mallocs per Sprintf("%g"): 4

R=golang-dev, gri
CC=golang-dev
https://golang.org/cl/5449106
2011-12-06 08:40:16 -08:00
Rob Pike
0a5508c692 various: we don't cast, we convert
R=golang-dev, dsymonds
CC=golang-dev
https://golang.org/cl/5437142
2011-12-05 19:40:52 -08:00
Rob Pike
2ed57a8cd8 fmt: only use Stringer or Error for strings
This is a slight change to fmt's semantics, but means that if you use
%d to print an integer with a Stringable value, it will print as an integer.
This came up because Time.Month() couldn't cleanly print as an integer
rather than a name. Using %d on Stringables is silly anyway, so there
should be no effect outside the fmt tests.
As a mild bonus, certain recursive failures of String methods
will also be avoided this way.

R=golang-dev, adg
CC=golang-dev
https://golang.org/cl/5453053
2011-12-05 16:45:51 -08:00
Russ Cox
2666b815a3 use new strconv API
All but 3 cases (in gcimporter.go and hixie.go)
are automatic conversions using gofix.

No attempt is made to use the new Append functions
even though there are definitely opportunities.

R=golang-dev, gri
CC=golang-dev
https://golang.org/cl/5447069
2011-12-05 15:48:46 -05:00
Russ Cox
434a6c85cb gc: use gofmt spacing when printing map type
R=ken2
CC=golang-dev
https://golang.org/cl/5450071
2011-12-02 14:45:07 -05:00
Rémy Oudompheng
8362ee99b0 fmt: don't check for nil when printing arrays as Go syntax.
Also add array values to printing test suite.
Fixes #2468.

R=golang-dev, r
CC=golang-dev, remy
https://golang.org/cl/5436053
2011-11-23 09:04:02 -08:00
Russ Cox
a7f1e10d24 fmt: distinguish empty vs nil slice/map in %#v
Also update Scanf tests to cope with DeepEqual
distinguishing empty vs nil slice.

R=golang-dev, bradfitz
CC=golang-dev
https://golang.org/cl/5375091
2011-11-14 16:10:58 -05:00
Rob Pike
30aa701fec renaming_2: gofix -r go1pkgrename src/pkg/[a-l]*
R=rsc
CC=golang-dev
https://golang.org/cl/5358041
2011-11-08 15:40:58 -08:00
Vincent Vanackere
eb1717e035 all: rename os.EOF to io.EOF in various non-code contexts
R=golang-dev, r
CC=golang-dev
https://golang.org/cl/5334050
2011-11-03 14:01:30 -07:00
Russ Cox
492098eb75 all: rename os.Error to error in various non-code contexts
R=adg
CC=golang-dev
https://golang.org/cl/5328062
2011-11-01 22:58:09 -04:00
Russ Cox
c2049d2dfe src/pkg/[a-m]*: gofix -r error -force=error
R=golang-dev, iant
CC=golang-dev
https://golang.org/cl/5322051
2011-11-01 22:04:37 -04:00
Luuk van Dijk
50110c9f83 gc: clean up printing.
Got rid of all the magic mystery globals. Now
for %N, %T, and %S, the flags +,- and # set a sticky
debug, sym and export mode, only visible in the new fmt.c.
Default is error mode. Handle h and l flags consistently with
the least side effects, so we can now change
things without worrying about unrelated things
breaking.

fixes #2361

R=rsc
CC=golang-dev
https://golang.org/cl/5316043
2011-10-31 18:09:40 +01:00
Russ Cox
0e81e508be fmt: handle os.Error values
Handling os.Error is no different than handling fmt.Stringer
here, so the code is redundant now, but it will be necessary
once error goes in.

Adding it now will make gofix fix it.

R=r
CC=golang-dev
https://golang.org/cl/5331045
2011-10-27 21:20:44 -07:00
Russ Cox
4e4eca2618 fmt: use rune
Lots of internal edits.

Formatter and Scanner interfaces change
(clients to be checked by govet).

R=r
CC=golang-dev
https://golang.org/cl/5305045
2011-10-25 22:21:33 -07:00
Rob Pike
d481d7c854 fmt: simplify the code some more by storing the field in the pp structure.
R=rsc
CC=golang-dev
https://golang.org/cl/5293058
2011-10-21 13:59:27 -07:00
Gustavo Niemeyer
526d0818cc fmt: don't panic formatting nil interfaces
R=golang-dev, r
CC=golang-dev
https://golang.org/cl/5296044
2011-10-19 18:26:08 -02:00
Rob Pike
811d334a65 fmt: clean up after reflect.Interface change.
Store the reflect.Value in the internal print state. Code is simpler, cleaner,
and a little faster - back to what it was before the change.

R=golang-dev, iant
CC=golang-dev
https://golang.org/cl/5299046
2011-10-18 16:23:07 -07:00
David Symonds
e45e324420 fmt: fix test relying on map iteration order.
This fixes the 386 builds.

R=golang-dev, adg, r
CC=golang-dev
https://golang.org/cl/5293043
2011-10-18 11:47:11 +11:00
Russ Cox
304cf4dc9b reflect: disallow Interface method on Value obtained via unexported name
Had been allowing it for use by fmt, but it is too hard to lock down.
Fix other packages not to depend on it.

R=r, r
CC=golang-dev
https://golang.org/cl/5266054
2011-10-17 18:48:45 -04:00
Rob Pike
aa2f439c6a fmt: remove an obsolete reference to os.ErrorString in a comment
R=golang-dev, bradfitz
CC=golang-dev
https://golang.org/cl/5229057
2011-10-12 13:50:08 -07:00
Brad Fitzpatrick
1444a08098 fmt: fix doc typo
R=golang-dev, r
CC=golang-dev
https://golang.org/cl/5252050
2011-10-11 08:49:09 -07:00
Rob Pike
12ad9b4315 fmt: replace channel cache with slice.
Simpler concept, and it turns a queue into a stack.
Speeds up benchmarks noticeably.

Before:
fmt_test.BenchmarkSprintfEmpty	10000000	       282 ns/op
fmt_test.BenchmarkSprintfString	 2000000	       910 ns/op
fmt_test.BenchmarkSprintfInt	 5000000	       723 ns/op
fmt_test.BenchmarkSprintfIntInt	 1000000	      1071 ns/op
fmt_test.BenchmarkSprintfPrefixedInt	 1000000	      1108 ns/op
fmt_test.BenchmarkScanInts	    1000	   2239510 ns/op
fmt_test.BenchmarkScanRecursiveInt	    1000	   2365432 ns/op

After:
fmt_test.BenchmarkSprintfEmpty	10000000	       232 ns/op
fmt_test.BenchmarkSprintfString	 2000000	       837 ns/op
fmt_test.BenchmarkSprintfInt	 5000000	       590 ns/op
fmt_test.BenchmarkSprintfIntInt	 2000000	       910 ns/op
fmt_test.BenchmarkSprintfPrefixedInt	 2000000	       996 ns/op
fmt_test.BenchmarkScanInts	    1000	   2210715 ns/op
fmt_test.BenchmarkScanRecursiveInt	    1000	   2367800 ns/op

R=rsc, r
CC=golang-dev
https://golang.org/cl/5151044
2011-09-29 11:23:06 -07:00
Rob Pike
b349cd2b0a fmt/fmt_test.go: count mallocs in a few more cases.
Interesting that Fprintf can do zero mallocs.
(Sprintf must allocate the returned string.)

R=golang-dev, bradfitz
CC=golang-dev
https://golang.org/cl/4977049
2011-09-02 11:47:15 +10:00
Rob Pike
583f72434f fmt: call UpdateMemStats in malloc counter
R=golang-dev, dsymonds
CC=golang-dev
https://golang.org/cl/4830059
2011-08-04 16:32:14 +10:00
Michael T. Jones
8cdee891d7 fmt: handle precision 0 format stings in standard way
The C-stdlib heritage of printf/fprintf/sprintf has two odd
aspects for precisions of zero with integers. First, the zero
can be specified in any of these ways, "%4.0d", "%.0d" and
"%.d" which was not previously supported here. Secondly, the
seemingly universal interpretation of precision for integers
is that precision==0 and value==0 means print nothing at all.
The code here now handles this for integers just as the code
in big/int.c does the same for the Int type. New tests are
added to fmt_test.go to verify these changes.

R=r, r
CC=golang-dev
https://golang.org/cl/4717045
2011-07-21 16:46:51 +10:00
Rob Pike
08e47ebb7d fmt: fix a couple of documentation glitches.
R=golang-dev, adg
CC=golang-dev
https://golang.org/cl/4758050
2011-07-18 11:44:27 +10:00
Rob Pike
f189308fb4 fmt: Scan(&int) was mishandling a lone zero.
It took it as an octal base prefix but assumed more digits were coming.
Fixes #2077.

R=golang-dev, dsymonds
CC=golang-dev
https://golang.org/cl/4764044
2011-07-18 10:05:35 +10:00
Robert Griesemer
90564a9256 go/printer: changed max. number of newlines from 3 to 2
manual changes in src/pkg/go/printer, src/cmd/gofix/signal_test.go
(cd src/cmd/gofix/testdata; gofmt -w *.in *.out)
(cd src/pkg/go/printer; gotest -update)
gofmt -w misc src

runs all tests

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/4715041
2011-07-14 14:39:40 -07:00
Brad Fitzpatrick
39acba55ee fmt: rename errno and error to err for doc consistency
The public godoc looked confused. I imagine these were
written before current conventions were established.

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/4662060
2011-06-28 11:00:31 -07:00
Michael T. Jones
d94e350f48 fmt: Added SkipSpace() function to fmt's ScanState interface.
Users of the Scan() infrastructure that employ ReadRune() rather than
Token() need a way to skip leading spaces and newlines as set by the
the parent, Fscan(), Fscanln, or Fscanf(). As the internal methods and
boolean flags are not exported, this new function was added here and
in the Int and Nat Scan() functions of the big package. (fmt.Rat did
not need change since it uses Token()) Also added Printf style format
code support to int types and tests for same to int_test.go

R=r, r, gri, mtj
CC=golang-dev
https://golang.org/cl/4634074
2011-06-24 17:26:45 -07:00
Robert Griesemer
712fb6dcd3 os.Error API: don't export os.ErrorString, use os.NewError consistently
This is a core API change.

1) gofix misc src
2) Manual adjustments to the following files under src/pkg:
   gob/decode.go
   rpc/client.go
   os/error.go
   io/io.go
   bufio/bufio.go
   http/request.go
   websocket/client.go
as well as:
   src/cmd/gofix/testdata/*.go.in (reverted)
   test/fixedbugs/bug243.go
3) Implemented gofix patch (oserrorstring.go) and test case (oserrorstring_test.go)

Compiles and runs all tests.

R=r, rsc, gri
CC=golang-dev
https://golang.org/cl/4607052
2011-06-22 10:52:47 -07:00
Rob Pike
97a929aac9 fmt: catch panics from calls to String etc.
This change causes Print et al. to catch panics generated by
calls to String, GoString, and Format.  The panic is formatted
into the output stream as an error, but the program continues.
As a special case, if the argument was a nil pointer, the
result is just "<nil>", because that's almost certainly enough
information and handles the very common case of String
methods that don't guard against nil.

Scan does not want this change. Input must work; output can
be for debugging and it's nice to get output even when you
make a mistake.

R=dsymonds, r, adg, gri, rsc, gri
CC=golang-dev
https://golang.org/cl/4640043
2011-06-21 08:31:02 +10:00
Russ Cox
21e75da486 respect goto restrictions
R=gri
CC=golang-dev
https://golang.org/cl/4625044
2011-06-17 06:07:13 -04:00
Rob Pike
d152fe74e1 fmt: debugging formats for characters: %+q %#U
%+q uses strconv.Quote[Rune]ToASCII, guaranteeing ASCII-only output.
%#U a quoted character if the rune is printable: 'x'=U+0078; otherwise
it's as before: U+000A.

R=golang-dev, gri, rsc
CC=golang-dev
https://golang.org/cl/4589047
2011-06-11 00:03:02 +00:00
Rob Pike
f2f3b8fa99 strconv: change Quote to be Unicode-friendly,
add QuoteToASCII.
The Quote and QuoteRune functions now let printable
runes (as defined by unicode.IsPrint) through.  When
true 7-bit clean stuff is necessary, there are now two
new functions: QuoteToASCII and QuoteRuneToASCII.

Printf("%q") uses Quote. To get the old behavior, it
will now be necessary to say
        Printf("%s", strconv.QuoteToASCII(s))
but that should rarely be necessary.

R=golang-dev, gri, r
CC=golang-dev
https://golang.org/cl/4561061
2011-06-07 12:23:08 +00:00
Rob Pike
ce5c1cf036 fmt: fix bug in UnreadRune: must clear memory of previous
rune if input implements UnreadRune; otherwise the lookahead
will lie.

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/4548082
2011-06-03 07:53:50 +10:00
Rob Pike
60dddc6db1 fmt: return EOF when out of input in Scan*.
Fixes #1840.

R=rsc
CC=golang-dev
https://golang.org/cl/4548077
2011-06-02 10:51:31 +10:00
Robert Griesemer
e8c87a7ddd fix build: temporarily disable the use of strings.Reader UnreadRune in fmt
R=r
CC=golang-dev
https://golang.org/cl/4532090
2011-05-26 11:54:10 -07:00
Rob Pike
7b03f2a990 fmt: make %q work for integers, printing a quoted character literal.
R=rsc
CC=golang-dev
https://golang.org/cl/4556060
2011-05-25 21:25:15 +10:00
Evan Shaw
3230fd1469 fmt: scanning doc fix
R=r
CC=golang-dev
https://golang.org/cl/4539073
2011-05-21 07:38:01 +10:00
Robert Griesemer
bda36cf3ab fmt: fix minor documentation nits
R=r, rsc
CC=golang-dev
https://golang.org/cl/4556041
2011-05-18 11:34:19 -07:00
Russ Cox
07abf1c732 fix tree for reflect rename
R=golang-dev, r
CC=golang-dev
https://golang.org/cl/4435067
2011-04-25 13:39:36 -04:00
Rob Pike
f3113ee9b9 fmt: tweak the doc for %U.
Fixes #1727.

R=rsc
CC=golang-dev
https://golang.org/cl/4437069
2011-04-23 11:25:27 -07:00
Ian Lance Taylor
14531fbaa5 fmt: decrease recursion depth
This permits the test to run when using gccgo on system
without split-stack support.  See
http://gcc.gnu.org/ml/gcc-patches/2011-04/msg01420.html
http://gcc.gnu.org/PR48553

R=r
CC=golang-dev
https://golang.org/cl/4440062
2011-04-22 16:59:21 -07:00
Rob Pike
4fe9f57413 fmt: allow %U for unsigned integers.
Suggested by jan.mercl@nic.cz.

R=rsc, jnml
CC=golang-dev
https://golang.org/cl/4376054
2011-04-12 11:03:05 -07:00
Russ Cox
db5c5d6fa6 update go tree for reflect changes
R=golang-dev, r
CC=golang-dev
https://golang.org/cl/4353043
2011-04-08 12:27:58 -04:00
Rob Pike
3907031358 fmt: implement precs for %q.
Also fix a bug: precision was in terms of bytes; should be runes.
Fixes #1652.

R=rsc, bradfitzgo, r2, bradfitzwork
CC=golang-dev
https://golang.org/cl/4280086
2011-03-31 14:56:01 -07:00
Russ Cox
b66b22cdd4 fmt: remove uintptrGetter type checks
This will make the fmt code easier to gofix
when the new reflect interface is ready.

R=r
CC=golang-dev
https://golang.org/cl/4324043
2011-03-30 22:12:30 -04:00
Rob Pike
7f9acb53cb testing: shorten some more tests
R=rsc
CC=golang-dev
https://golang.org/cl/4314044
2011-03-26 11:25:22 -07:00
Rob Pike
a16af59fd1 fmt: heaven forfend we export EOF = -1
R=adg
CC=golang-dev
https://golang.org/cl/4248076
2011-03-09 16:53:32 -08:00