remove some naked returns and simplify

This commit is contained in:
Matt Jaffee 2018-09-12 17:21:17 -05:00
parent 70e9da3b75
commit 3bc9c66f5e
No known key found for this signature in database
GPG key ID: 08A3DFFF987B11BF
2 changed files with 7 additions and 15 deletions

8
api.go
View file

@ -314,8 +314,7 @@ func (api *API) Field(_ context.Context, indexName, fieldName string) (*Field, e
// in one long bitmap.
func (api *API) ImportRoaringBytes(ctx context.Context, roaringBytes []byte, indexName, fieldName string, shard uint64) (err error) {
if err = api.validate(apiField); err != nil {
err = errors.Wrap(err, "validating api method")
return
return errors.Wrap(err, "validating api method")
}
nodes := api.cluster.shardNodes(indexName, shard)
var wg sync.WaitGroup
@ -324,8 +323,7 @@ func (api *API) ImportRoaringBytes(ctx context.Context, roaringBytes []byte, ind
if node.ID == api.server.nodeID {
field := api.holder.Field(indexName, fieldName)
if field == nil {
err = newNotFoundError(ErrFieldNotFound)
return
return newNotFoundError(ErrFieldNotFound)
}
wg.Add(1)
go func(node *Node) {
@ -344,7 +342,7 @@ func (api *API) ImportRoaringBytes(ctx context.Context, roaringBytes []byte, ind
}
wg.Wait()
return
return err
}
// DeleteField removes the named field from the named index. If the index is not

View file

@ -3434,10 +3434,7 @@ func (b *Bitmap) UnmarshalBinary(data []byte) error {
// Read container offsets and attach data.
if haveRuns {
err := readWithRuns(b, data, pos, keyN)
if err != nil {
return errors.Wrap(err, "reading runs from standard roaring format")
}
readWithRuns(b, data, pos, keyN)
} else {
err := readOffsets(b, data, pos, keyN)
if err != nil {
@ -3447,7 +3444,7 @@ func (b *Bitmap) UnmarshalBinary(data []byte) error {
return nil
}
func readOffsets(b *Bitmap, data []byte, pos int, keyN uint32) (err error) {
func readOffsets(b *Bitmap, data []byte, pos int, keyN uint32) error {
citer, _ := b.Containers.Iterator(0)
for i, buf := 0, data[pos:]; i < int(keyN); i, buf = i+1, buf[4:] {
@ -3473,11 +3470,10 @@ func readOffsets(b *Bitmap, data []byte, pos int, keyN uint32) (err error) {
return fmt.Errorf("unsupported container type %d", c.containerType)
}
}
return
return nil
}
func readWithRuns(b *Bitmap, data []byte, pos int, keyN uint32) (err error) {
func readWithRuns(b *Bitmap, data []byte, pos int, keyN uint32) {
citer, _ := b.Containers.Iterator(0)
for i := 0; i < int(keyN); i++ {
citer.Next()
@ -3505,6 +3501,4 @@ func readWithRuns(b *Bitmap, data []byte, pos int, keyN uint32) (err error) {
pos += bitmapN * 8
}
}
return
}