storage: Don't check completion state on every write

This commit is contained in:
Matt Joiner 2018-01-12 10:45:19 +11:00
parent f3ff3821ec
commit d5e2d7ce99
1 changed files with 9 additions and 6 deletions

View File

@ -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")
}