Commit 66e44000 authored by Robert Griesemer's avatar Robert Griesemer

godoc: use new index/suffixarray serialization code

When saving/restoring the fulltext index, the entire
respective suffixarray is now saved/restored (as opposed
to the indexed data only, and the suffixarray recreated).
This saves significant start-up time for large indexes,
at the cost of significantly larger index files.

R=r
CC=golang-dev
https://golang.org/cl/5037043
parent bd80b119
...@@ -834,30 +834,36 @@ func NewIndex(dirnames <-chan string, fulltextIndex bool, throttle float64) *Ind ...@@ -834,30 +834,36 @@ func NewIndex(dirnames <-chan string, fulltextIndex bool, throttle float64) *Ind
} }
type fileIndex struct { type fileIndex struct {
Sources []byte
Words map[string]*LookupResult Words map[string]*LookupResult
Alts map[string]*AltWords Alts map[string]*AltWords
Snippets []*Snippet Snippets []*Snippet
Fulltext bool
} }
// Write writes the index x to w. // Write writes the index x to w.
func (x *Index) Write(w io.Writer) os.Error { func (x *Index) Write(w io.Writer) os.Error {
var sources []byte fulltext := false
if x.suffixes != nil { if x.suffixes != nil {
// fulltext index present fulltext = true
sources = x.suffixes.Bytes()
} }
fx := fileIndex{ fx := fileIndex{
sources, // indicates if fulltext index is present or not
x.words, x.words,
x.alts, x.alts,
x.snippets, x.snippets,
fulltext,
} }
err := gob.NewEncoder(w).Encode(fx) if err := gob.NewEncoder(w).Encode(fx); err != nil {
if err == nil && sources != nil { return err
err = x.fset.Write(w) }
if fulltext {
if err := x.fset.Write(w); err != nil {
return err
}
if err := x.suffixes.Write(w); err != nil {
return err
}
} }
return err return nil
} }
// Read reads the index from r into x; x must not be nil. // Read reads the index from r into x; x must not be nil.
...@@ -866,17 +872,19 @@ func (x *Index) Read(r io.Reader) os.Error { ...@@ -866,17 +872,19 @@ func (x *Index) Read(r io.Reader) os.Error {
if err := gob.NewDecoder(r).Decode(&fx); err != nil { if err := gob.NewDecoder(r).Decode(&fx); err != nil {
return err return err
} }
if fx.Sources != nil { x.words = fx.Words
// fulltext index is present x.alts = fx.Alts
x.snippets = fx.Snippets
if fx.Fulltext {
x.fset = token.NewFileSet() x.fset = token.NewFileSet()
if err := x.fset.Read(r); err != nil { if err := x.fset.Read(r); err != nil {
return err return err
} }
x.suffixes = suffixarray.New(fx.Sources) x.suffixes = new(suffixarray.Index)
if err := x.suffixes.Read(r); err != nil {
return err
}
} }
x.words = fx.Words
x.alts = fx.Alts
x.snippets = fx.Snippets
return nil return nil
} }
......
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