aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Griesemer <gri@golang.org>2011-08-31 14:01:58 -0700
committerRobert Griesemer <gri@golang.org>2011-08-31 14:01:58 -0700
commit3f1269ff1ea56cd4d1608a2b6285d12b5b1dc7d2 (patch)
tree6b91e88ea7ef81f239e6f696a37154f99ed02041
parenta31f317a990ad663e24b3521a958705280c14733 (diff)
downloadgo-3f1269ff1ea56cd4d1608a2b6285d12b5b1dc7d2.tar.gz
go-3f1269ff1ea56cd4d1608a2b6285d12b5b1dc7d2.zip
godoc: more index size reduction
- KindRuns don't need to repeat SpotKind, it is stored in each Spot - removed extra indirection from FileRuns to KindRuns - slight reduction of written index size (~500KB) R=rsc CC=golang-dev https://golang.org/cl/4969052
-rw-r--r--lib/godoc/search.html6
-rw-r--r--src/cmd/godoc/godoc.go4
-rw-r--r--src/cmd/godoc/index.go37
3 files changed, 22 insertions, 25 deletions
diff --git a/lib/godoc/search.html b/lib/godoc/search.html
index 36c34f54d8..9fdd6ddc37 100644
--- a/lib/godoc/search.html
+++ b/lib/godoc/search.html
@@ -26,7 +26,7 @@
{{range .Files}}
{{$src_html := srcLink .File.Path | html}}
{{range .Groups}}
- {{range .Infos}}
+ {{range .}}
<a href="/{{$src_html}}?h={{$query_url}}#L{{infoLine .}}">{{$src_html}}:{{infoLine .}}</a>
{{infoSnippet_html .}}
{{end}}
@@ -46,10 +46,10 @@
{{range .Groups}}
<tr>
<td width="25"></td>
- <th align="left" valign="top">{{infoKind_html .Kind}}</th>
+ <th align="left" valign="top">{{index . 0 | infoKind_html}}</th>
<td align="left" width="4"></td>
<td>
- {{range .Infos}}
+ {{range .}}
<a href="/{{$src_html}}?h={{$query_url}}#L{{infoLine .}}">{{infoLine .}}</a>
{{end}}
</td>
diff --git a/src/cmd/godoc/godoc.go b/src/cmd/godoc/godoc.go
index c172235168..a4e26b8726 100644
--- a/src/cmd/godoc/godoc.go
+++ b/src/cmd/godoc/godoc.go
@@ -406,8 +406,8 @@ var infoKinds = [nKinds]string{
Use: "use",
}
-func infoKind_htmlFunc(kind SpotKind) string {
- return infoKinds[kind] // infoKind entries are html-escaped
+func infoKind_htmlFunc(info SpotInfo) string {
+ return infoKinds[info.Kind()] // infoKind entries are html-escaped
}
func infoLineFunc(info SpotInfo) int {
diff --git a/src/cmd/godoc/index.go b/src/cmd/godoc/index.go
index 28ef26fc12..b99363491b 100644
--- a/src/cmd/godoc/index.go
+++ b/src/cmd/godoc/index.go
@@ -7,7 +7,7 @@
//
// Algorithm for identifier index:
// - traverse all .go files of the file tree specified by root
-// - for each word (identifier) encountered, collect all occurrences (spots)
+// - for each identifier (word) encountered, collect all occurrences (spots)
// into a list; this produces a list of spots for each word
// - reduce the lists: from a list of spots to a list of FileRuns,
// and from a list of FileRuns into a list of PakRuns
@@ -179,28 +179,25 @@ func (x SpotInfo) IsIndex() bool { return x&1 != 0 }
const removeDuplicates = true
// A KindRun is a run of SpotInfos of the same kind in a given file.
-type KindRun struct {
- Kind SpotKind
- Infos []SpotInfo
-}
+// The kind (3 bits) is stored in each SpotInfo element; to find the
+// kind of a KindRun, look at any of it's elements.
+type KindRun []SpotInfo
// KindRuns are sorted by line number or index. Since the isIndex bit
// is always the same for all infos in one list we can compare lori's.
-func (f *KindRun) Len() int { return len(f.Infos) }
-func (f *KindRun) Less(i, j int) bool { return f.Infos[i].Lori() < f.Infos[j].Lori() }
-func (f *KindRun) Swap(i, j int) { f.Infos[i], f.Infos[j] = f.Infos[j], f.Infos[i] }
+func (k KindRun) Len() int { return len(k) }
+func (k KindRun) Less(i, j int) bool { return k[i].Lori() < k[j].Lori() }
+func (k KindRun) Swap(i, j int) { k[i], k[j] = k[j], k[i] }
// FileRun contents are sorted by Kind for the reduction into KindRuns.
func lessKind(x, y interface{}) bool { return x.(SpotInfo).Kind() < y.(SpotInfo).Kind() }
// newKindRun allocates a new KindRun from the SpotInfo run h.
func newKindRun(h RunList) interface{} {
- kind := h[0].(SpotInfo).Kind()
- infos := make([]SpotInfo, len(h))
+ run := make(KindRun, len(h))
for i, x := range h {
- infos[i] = x.(SpotInfo)
+ run[i] = x.(SpotInfo)
}
- run := &KindRun{kind, infos}
// Spots were sorted by file and kind to create this run.
// Within this run, sort them by line number or index.
@@ -212,15 +209,15 @@ func newKindRun(h RunList) interface{} {
// bit is always the same for all infos in one
// list we can simply compare the entire info.
k := 0
- var prev SpotInfo
- for i, x := range infos {
- if x != prev || i == 0 {
- infos[k] = x
+ prev := SpotInfo(1<<32 - 1) // an unlikely value
+ for _, x := range run {
+ if x != prev {
+ run[k] = x
k++
prev = x
}
}
- run.Infos = infos[0:k]
+ run = run[0:k]
}
return run
@@ -260,7 +257,7 @@ type Spot struct {
// A FileRun is a list of KindRuns belonging to the same file.
type FileRun struct {
File *File
- Groups []*KindRun
+ Groups []KindRun
}
// Spots are sorted by file path for the reduction into FileRuns.
@@ -285,9 +282,9 @@ func newFileRun(h RunList) interface{} {
h2 := h1.reduce(lessKind, newKindRun)
// create the FileRun
- groups := make([]*KindRun, len(h2))
+ groups := make([]KindRun, len(h2))
for i, x := range h2 {
- groups[i] = x.(*KindRun)
+ groups[i] = x.(KindRun)
}
return &FileRun{file, groups}
}