Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
go
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
go
Commits
668418d1
Commit
668418d1
authored
Feb 06, 2012
by
Robert Griesemer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
go/token: remove dependency on encoding/gob
R=dsymonds CC=golang-dev
https://golang.org/cl/5636053
parent
1f133e2b
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
23 additions
and
24 deletions
+23
-24
src/cmd/godoc/index.go
src/cmd/godoc/index.go
+8
-2
src/pkg/go/token/serialize.go
src/pkg/go/token/serialize.go
+6
-20
src/pkg/go/token/serialize_test.go
src/pkg/go/token/serialize_test.go
+9
-2
No files found.
src/cmd/godoc/index.go
View file @
668418d1
...
@@ -867,7 +867,10 @@ func (x *Index) Write(w io.Writer) error {
...
@@ -867,7 +867,10 @@ func (x *Index) Write(w io.Writer) error {
return
err
return
err
}
}
if
fulltext
{
if
fulltext
{
if
err
:=
x
.
fset
.
Write
(
w
);
err
!=
nil
{
encode
:=
func
(
x
interface
{})
error
{
return
gob
.
NewEncoder
(
w
)
.
Encode
(
x
)
}
if
err
:=
x
.
fset
.
Write
(
encode
);
err
!=
nil
{
return
err
return
err
}
}
if
err
:=
x
.
suffixes
.
Write
(
w
);
err
!=
nil
{
if
err
:=
x
.
suffixes
.
Write
(
w
);
err
!=
nil
{
...
@@ -897,7 +900,10 @@ func (x *Index) Read(r io.Reader) error {
...
@@ -897,7 +900,10 @@ func (x *Index) Read(r io.Reader) error {
return
err
return
err
}
}
x
.
suffixes
=
new
(
suffixarray
.
Index
)
x
.
suffixes
=
new
(
suffixarray
.
Index
)
if
err
:=
x
.
suffixes
.
Read
(
r
);
err
!=
nil
{
decode
:=
func
(
x
interface
{})
error
{
return
gob
.
NewDecoder
(
r
)
.
Decode
(
x
)
}
if
err
:=
x
.
suffixes
.
Read
(
decode
);
err
!=
nil
{
return
err
return
err
}
}
}
}
...
...
src/pkg/go/token/serialize.go
View file @
668418d1
...
@@ -4,11 +4,6 @@
...
@@ -4,11 +4,6 @@
package
token
package
token
import
(
"encoding/gob"
"io"
)
type
serializedFile
struct
{
type
serializedFile
struct
{
// fields correspond 1:1 to fields with same (lower-case) name in File
// fields correspond 1:1 to fields with same (lower-case) name in File
Name
string
Name
string
...
@@ -23,19 +18,10 @@ type serializedFileSet struct {
...
@@ -23,19 +18,10 @@ type serializedFileSet struct {
Files
[]
serializedFile
Files
[]
serializedFile
}
}
func
(
s
*
serializedFileSet
)
Read
(
r
io
.
Reader
)
error
{
// Read calls decode to deserialize a file set into s; s must not be nil.
return
gob
.
NewDecoder
(
r
)
.
Decode
(
s
)
func
(
s
*
FileSet
)
Read
(
decode
func
(
interface
{})
error
)
error
{
}
func
(
s
*
serializedFileSet
)
Write
(
w
io
.
Writer
)
error
{
return
gob
.
NewEncoder
(
w
)
.
Encode
(
s
)
}
// Read reads the fileset from r into s; s must not be nil.
// If r does not also implement io.ByteReader, it will be wrapped in a bufio.Reader.
func
(
s
*
FileSet
)
Read
(
r
io
.
Reader
)
error
{
var
ss
serializedFileSet
var
ss
serializedFileSet
if
err
:=
ss
.
Read
(
r
);
err
!=
nil
{
if
err
:=
decode
(
&
ss
);
err
!=
nil
{
return
err
return
err
}
}
...
@@ -53,8 +39,8 @@ func (s *FileSet) Read(r io.Reader) error {
...
@@ -53,8 +39,8 @@ func (s *FileSet) Read(r io.Reader) error {
return
nil
return
nil
}
}
// Write
writes the fileset s to w
.
// Write
calls encode to serialize the file set s
.
func
(
s
*
FileSet
)
Write
(
w
io
.
Write
r
)
error
{
func
(
s
*
FileSet
)
Write
(
encode
func
(
interface
{})
erro
r
)
error
{
var
ss
serializedFileSet
var
ss
serializedFileSet
s
.
mutex
.
Lock
()
s
.
mutex
.
Lock
()
...
@@ -66,5 +52,5 @@ func (s *FileSet) Write(w io.Writer) error {
...
@@ -66,5 +52,5 @@ func (s *FileSet) Write(w io.Writer) error {
ss
.
Files
=
files
ss
.
Files
=
files
s
.
mutex
.
Unlock
()
s
.
mutex
.
Unlock
()
return
ss
.
Write
(
w
)
return
encode
(
ss
)
}
}
src/pkg/go/token/serialize_test.go
View file @
668418d1
...
@@ -6,6 +6,7 @@ package token
...
@@ -6,6 +6,7 @@ package token
import
(
import
(
"bytes"
"bytes"
"encoding/gob"
"fmt"
"fmt"
"testing"
"testing"
)
)
...
@@ -69,12 +70,18 @@ func equal(p, q *FileSet) error {
...
@@ -69,12 +70,18 @@ func equal(p, q *FileSet) error {
func
checkSerialize
(
t
*
testing
.
T
,
p
*
FileSet
)
{
func
checkSerialize
(
t
*
testing
.
T
,
p
*
FileSet
)
{
var
buf
bytes
.
Buffer
var
buf
bytes
.
Buffer
if
err
:=
p
.
Write
(
&
buf
);
err
!=
nil
{
encode
:=
func
(
x
interface
{})
error
{
return
gob
.
NewEncoder
(
&
buf
)
.
Encode
(
x
)
}
if
err
:=
p
.
Write
(
encode
);
err
!=
nil
{
t
.
Errorf
(
"writing fileset failed: %s"
,
err
)
t
.
Errorf
(
"writing fileset failed: %s"
,
err
)
return
return
}
}
q
:=
NewFileSet
()
q
:=
NewFileSet
()
if
err
:=
q
.
Read
(
&
buf
);
err
!=
nil
{
decode
:=
func
(
x
interface
{})
error
{
return
gob
.
NewDecoder
(
&
buf
)
.
Decode
(
x
)
}
if
err
:=
q
.
Read
(
decode
);
err
!=
nil
{
t
.
Errorf
(
"reading fileset failed: %s"
,
err
)
t
.
Errorf
(
"reading fileset failed: %s"
,
err
)
return
return
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment