storage: Don't check completion state on every write
This commit is contained in:
parent
f3ff3821ec
commit
d5e2d7ce99
|
@ -1,7 +1,6 @@
|
|||
package storage
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"io"
|
||||
"os"
|
||||
|
||||
|
@ -37,11 +36,15 @@ type Piece struct {
|
|||
}
|
||||
|
||||
func (p Piece) WriteAt(b []byte, off int64) (n int, err error) {
|
||||
c := p.Completion()
|
||||
if c.Ok && c.Complete {
|
||||
err = errors.New("piece already completed")
|
||||
return
|
||||
}
|
||||
// Callers should not be writing to completed pieces, but it's too
|
||||
// expensive to be checking this on every single write using uncached
|
||||
// completions.
|
||||
|
||||
// c := p.Completion()
|
||||
// if c.Ok && c.Complete {
|
||||
// err = errors.New("piece already completed")
|
||||
// return
|
||||
// }
|
||||
if off+int64(len(b)) > p.mip.Length() {
|
||||
panic("write overflows piece")
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue