Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix staticcheck errors #67

Merged
merged 1 commit into from
Apr 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 11 additions & 14 deletions car.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,17 +183,16 @@ func loadCarFast(s batchStore, cr *CarReader) (*CarHeader, error) {
var buf []blocks.Block
for {
blk, err := cr.Next()
switch err {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if there was a reason to use a switch here. Performance maybe, since this is a function that's supposedly "fast"?
If I remember correctly though, switch is not faster than if / else, unless you have a lot of cases.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I honestly don't think it matters here, either.

For those reading this later, the warning is:

default case should be first or last in switch statement (ST1015)

It's entirely reasonable. I also think the if/else method is simpler.

case io.EOF:
if len(buf) > 0 {
if err := s.PutMany(buf); err != nil {
return nil, err
if err != nil {
if err == io.EOF {
if len(buf) > 0 {
if err := s.PutMany(buf); err != nil {
return nil, err
}
}
return cr.Header, nil
}
return cr.Header, nil
default:
return nil, err
case nil:
}

buf = append(buf, blk)
Expand All @@ -208,15 +207,13 @@ func loadCarFast(s batchStore, cr *CarReader) (*CarHeader, error) {
}

func loadCarSlow(s Store, cr *CarReader) (*CarHeader, error) {

for {
blk, err := cr.Next()
switch err {
case io.EOF:
return cr.Header, nil
default:
if err != nil {
if err == io.EOF {
return cr.Header, nil
}
return nil, err
case nil:
}

if err := s.Put(blk); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion selectivecar.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ func (sct *selectiveCarTraverser) traverseHeader() error {
func (sct *selectiveCarTraverser) loader(lnk ipld.Link, ctx ipld.LinkContext) (io.Reader, error) {
cl, ok := lnk.(cidlink.Link)
if !ok {
return nil, errors.New("Incorrect Link Type")
return nil, errors.New("incorrect link type")
}
c := cl.Cid
blk, err := sct.sc.store.Get(c)
Expand Down