From 18e6f9daa3899318d36b525b068837f49bc2c1cf Mon Sep 17 00:00:00 2001 From: ferhat elmas Date: Wed, 29 Nov 2017 02:24:31 +0100 Subject: all: simplification - no length for map initialization - don't check for boolean/error return - don't format string - use string method of bytes buffer instead of converting bytes to string - use `strings.Contains` instead of `strings.Index` - use `bytes.Equal` instead of `bytes.Compare` --- plumbing/format/index/decoder.go | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'plumbing/format/index/decoder.go') diff --git a/plumbing/format/index/decoder.go b/plumbing/format/index/decoder.go index 5bf6a52..1a58128 100644 --- a/plumbing/format/index/decoder.go +++ b/plumbing/format/index/decoder.go @@ -200,11 +200,8 @@ func (d *Decoder) padEntry(idx *Index, e *Entry, read int) error { entrySize := read + len(e.Name) padLen := 8 - entrySize%8 - if _, err := io.CopyN(ioutil.Discard, d.r, int64(padLen)); err != nil { - return err - } - - return nil + _, err := io.CopyN(ioutil.Discard, d.r, int64(padLen)) + return err } func (d *Decoder) readExtensions(idx *Index) error { @@ -288,7 +285,7 @@ func (d *Decoder) readChecksum(expected []byte, alreadyRead [4]byte) error { return err } - if bytes.Compare(h[:], expected) != 0 { + if !bytes.Equal(h[:], expected) { return ErrInvalidChecksum } @@ -407,7 +404,7 @@ func (d *resolveUndoDecoder) Decode(ru *ResolveUndo) error { func (d *resolveUndoDecoder) readEntry() (*ResolveUndoEntry, error) { e := &ResolveUndoEntry{ - Stages: make(map[Stage]plumbing.Hash, 0), + Stages: make(map[Stage]plumbing.Hash), } path, err := binary.ReadUntil(d.r, '\x00') -- cgit