Commit ec9ea9a5 authored by Robert Griesemer's avatar Robert Griesemer

godoc: use a bufio.Buffer to read search index

Also: Minor refactoring for cleanliness and symmetry.

Fixes #2286.

R=r
CC=golang-dev
https://golang.org/cl/5232041
parent 3e466999
......@@ -38,6 +38,7 @@
package main
import (
"bufio"
"bytes"
"go/ast"
"go/parser"
......@@ -840,6 +841,14 @@ type fileIndex struct {
Fulltext bool
}
func (x *fileIndex) Write(w io.Writer) os.Error {
return gob.NewEncoder(w).Encode(x)
}
func (x *fileIndex) Read(r io.Reader) os.Error {
return gob.NewDecoder(r).Decode(x)
}
// Write writes the index x to w.
func (x *Index) Write(w io.Writer) os.Error {
fulltext := false
......@@ -852,7 +861,7 @@ func (x *Index) Write(w io.Writer) os.Error {
x.snippets,
fulltext,
}
if err := gob.NewEncoder(w).Encode(fx); err != nil {
if err := fx.Write(w); err != nil {
return err
}
if fulltext {
......@@ -867,9 +876,14 @@ func (x *Index) Write(w io.Writer) os.Error {
}
// Read reads the index from r into x; x must not be nil.
// If r does not also implement io.ByteReader, it will be wrapped in a bufio.Reader.
func (x *Index) Read(r io.Reader) os.Error {
// We use the ability to read bytes as a plausible surrogate for buffering.
if _, ok := r.(io.ByteReader); !ok {
r = bufio.NewReader(r)
}
var fx fileIndex
if err := gob.NewDecoder(r).Decode(&fx); err != nil {
if err := fx.Read(r); err != nil {
return err
}
x.words = fx.Words
......
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