aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Pike <r@golang.org>2011-02-14 11:47:19 -0800
committerRob Pike <r@golang.org>2011-02-14 11:47:19 -0800
commit29ae8e9a986f9597c922ceae8266b49bf47dc2b7 (patch)
tree3872357f56be81ba7af268d5445a96cc5fdc5acd
parent7115eef6beb4f359245d2770bc6b4c6aa0ae25e1 (diff)
downloadgo-29ae8e9a986f9597c922ceae8266b49bf47dc2b7.tar.gz
go-29ae8e9a986f9597c922ceae8266b49bf47dc2b7.zip
makehtml: use append
The program is old and missed its opportunity. R=gri, adg CC=golang-dev https://golang.org/cl/4178050
-rw-r--r--doc/htmlgen.go24
1 files changed, 5 insertions, 19 deletions
diff --git a/doc/htmlgen.go b/doc/htmlgen.go
index 5d0bad8b59..4d68767c30 100644
--- a/doc/htmlgen.go
+++ b/doc/htmlgen.go
@@ -18,13 +18,13 @@ import (
)
var (
- lines = make([][]byte, 0, 10000) // assume big enough
- linebuf = make([]byte, 10000) // assume big enough
+ lines = make([][]byte, 0, 2000) // probably big enough; grows if not
empty = []byte("")
newline = []byte("\n")
tab = []byte("\t")
quote = []byte(`"`)
+ indent = []byte{' ', ' ', ' ', ' '}
sectionMarker = []byte("----\n")
preStart = []byte("<pre>")
@@ -52,9 +52,7 @@ func read() {
if err != nil {
log.Fatal(err)
}
- n := len(lines)
- lines = lines[0 : n+1]
- lines[n] = line
+ lines = append(lines, line)
}
}
@@ -173,19 +171,7 @@ func trim(l []byte) []byte {
return l
}
-// expand tabs to 4 spaces. don't worry about columns.
+// expand tabs to spaces. don't worry about columns.
func expandTabs(l []byte) []byte {
- j := 0 // position in linebuf.
- for _, c := range l {
- if c == '\t' {
- for k := 0; k < 4; k++ {
- linebuf[j] = ' '
- j++
- }
- } else {
- linebuf[j] = c
- j++
- }
- }
- return linebuf[0:j]
+ return bytes.Replace(l, tab, indent, -1)
}