Inlineable `(*File).BytesCompleted()` (#612)

This commit is contained in:
YenForYang 2021-09-14 07:11:35 -05:00 committed by GitHub
parent be8b7b7d35
commit 57b4e78b0f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 4 deletions

View File

@ -44,13 +44,14 @@ func (f *File) Length() int64 {
// Number of bytes of the entire file we have completed. This is the sum of
// completed pieces, and dirtied chunks of incomplete pieces.
func (f *File) BytesCompleted() int64 {
func (f *File) BytesCompleted() (n int64) {
f.t.cl.rLock()
defer f.t.cl.rUnlock()
return f.bytesCompleted()
n = f.bytesCompletedLocked()
f.t.cl.rUnlock()
return
}
func (f *File) bytesCompleted() int64 {
func (f *File) bytesCompletedLocked() int64 {
return f.length - f.bytesLeft()
}