Commit 3f1269ff authored by Robert Griesemer's avatar Robert Griesemer

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
parent a31f317a
......@@ -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>
......
......@@ -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 {
......
......@@ -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}
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment