mirror of
https://github.com/golang/go
synced 2024-11-20 10:54:49 -07:00
godoc: use file instead of file set for computing line info
Reduces indexing time by ~10%; from ~44s to ~39s, best of 3 runs. R=rsc CC=golang-dev https://golang.org/cl/3510041
This commit is contained in:
parent
1612b8734a
commit
4ba27e27f3
@ -432,6 +432,7 @@ type Indexer struct {
|
|||||||
fset *token.FileSet // file set for all indexed files
|
fset *token.FileSet // file set for all indexed files
|
||||||
words map[string]*IndexResult // RunLists of Spots
|
words map[string]*IndexResult // RunLists of Spots
|
||||||
snippets vector.Vector // vector of *Snippets, indexed by snippet indices
|
snippets vector.Vector // vector of *Snippets, indexed by snippet indices
|
||||||
|
current *token.File // last file added to file set
|
||||||
file *File // current file
|
file *File // current file
|
||||||
decl ast.Decl // current decl
|
decl ast.Decl // current decl
|
||||||
nspots int // number of spots encountered
|
nspots int // number of spots encountered
|
||||||
@ -462,7 +463,7 @@ func (x *Indexer) visitIdent(kind SpotKind, id *ast.Ident) {
|
|||||||
|
|
||||||
if kind == Use || x.decl == nil {
|
if kind == Use || x.decl == nil {
|
||||||
// not a declaration or no snippet required
|
// not a declaration or no snippet required
|
||||||
info := makeSpotInfo(kind, x.fset.Position(id.Pos()).Line, false)
|
info := makeSpotInfo(kind, x.current.Line(id.Pos()), false)
|
||||||
lists.Others.Push(Spot{x.file, info})
|
lists.Others.Push(Spot{x.file, info})
|
||||||
} else {
|
} else {
|
||||||
// a declaration with snippet
|
// a declaration with snippet
|
||||||
@ -608,6 +609,7 @@ func (x *Indexer) visitFile(dirname string, f *os.FileInfo) {
|
|||||||
return // ignore files with (parse) errors
|
return // ignore files with (parse) errors
|
||||||
}
|
}
|
||||||
|
|
||||||
|
x.current = x.fset.File(file.Pos()) // file.Pos is in the current file
|
||||||
dir, _ := pathutil.Split(path)
|
dir, _ := pathutil.Split(path)
|
||||||
pak := Pak{dir, file.Name.Name}
|
pak := Pak{dir, file.Name.Name}
|
||||||
x.file = &File{path, pak}
|
x.file = &File{path, pak}
|
||||||
@ -658,8 +660,9 @@ func NewIndex(dirnames <-chan string) *Index {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// the file set is not needed after indexing - help GC and clear it
|
// the file set and current file are not needed after indexing - help GC and clear them
|
||||||
x.fset = nil
|
x.fset = nil
|
||||||
|
x.current = nil // contains reference to fset!
|
||||||
|
|
||||||
// for each word, reduce the RunLists into a LookupResult;
|
// for each word, reduce the RunLists into a LookupResult;
|
||||||
// also collect the word with its canonical spelling in a
|
// also collect the word with its canonical spelling in a
|
||||||
|
Loading…
Reference in New Issue
Block a user