Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
G
golang
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
golang
Commits
d984f989
Commit
d984f989
authored
Dec 03, 2009
by
Rob Pike
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
minor improvement to formatting: don't allocate padding strings every time.
R=rsc
https://golang.org/cl/164090
parent
272d1563
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
12 deletions
+19
-12
format.go
src/pkg/fmt/format.go
+19
-12
No files found.
src/pkg/fmt/format.go
View file @
d984f989
...
...
@@ -8,12 +8,22 @@ import (
"strconv"
;
)
const
(
nByte
=
64
;
nPows10
=
160
;
const
nByte
=
64
const
nPows10
=
160
ldigits
=
"0123456789abcdef"
;
udigits
=
"0123456789ABCDEF"
;
)
var
ldigits
string
=
"0123456789abcdef"
// var not const because we take its address
var
udigits
string
=
"0123456789ABCDEF"
const
padZeros
=
"0000000000000000000000000000000000000000000000000000000000000000"
const
padSpaces
=
" "
func
init
()
{
if
len
(
padZeros
)
!=
nByte
||
len
(
padSpaces
)
!=
nByte
{
panic
(
"fmt padding wrong length"
)
}
}
/*
Fmt is the raw formatter used by Printf etc. Not meant for normal use.
...
...
@@ -125,22 +135,19 @@ func (f *Fmt) pad(s string) {
w
=
-
w
;
}
w
-=
len
(
s
);
pad
char
:=
byte
(
' '
)
;
pad
ding
:=
padSpaces
;
if
left
&&
f
.
zero
{
pad
char
=
'0'
pad
ding
=
padZeros
}
if
w
>
0
{
if
w
>
nByte
{
w
=
nByte
}
buf
:=
make
([]
byte
,
w
);
for
i
:=
0
;
i
<
w
;
i
++
{
buf
[
i
]
=
padchar
}
padding
=
padding
[
0
:
w
];
if
left
{
s
=
string
(
buf
)
+
s
s
=
padding
+
s
}
else
{
s
=
s
+
string
(
buf
)
s
+=
padding
}
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment