[REV] git packfile, avoid allocating in teeReader.ReadByte

This commit is contained in:
barnett 2018-04-20 11:00:07 +08:00
parent 7aac3a6106
commit ca5a1280dc
2 changed files with 7 additions and 5 deletions

View File

@ -36,7 +36,7 @@ func TestGitClone(t *testing.T) {
Branch: "master",
}
//logger := event.GetManager().GetLogger("system")
res, err := GitClone(csi, "/tmp/rainbonddoc", nil, 1)
res, err := GitClone(csi, "/tmp/rainbonddoc2", nil, 1)
if err != nil {
t.Fatal(err)
}

View File

@ -64,8 +64,8 @@ func NewScanner(r io.Reader) *Scanner {
crc := crc32.NewIEEE()
return &Scanner{
r: &teeReader{
newByteReadSeeker(seeker),
crc,
reader: newByteReadSeeker(seeker),
w: crc,
},
crc: crc,
IsSeekable: ok,
@ -400,7 +400,8 @@ type reader interface {
type teeReader struct {
reader
w hash.Hash32
w hash.Hash32
buf [1]byte
}
func (r *teeReader) Read(p []byte) (n int, err error) {
@ -416,7 +417,8 @@ func (r *teeReader) Read(p []byte) (n int, err error) {
func (r *teeReader) ReadByte() (b byte, err error) {
b, err = r.reader.ReadByte()
if err == nil {
_, err := r.w.Write([]byte{b})
r.buf[0] = b
_, err := r.w.Write(r.buf[:])
if err != nil {
return 0, err
}