]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Inlineable `(*File).BytesCompleted()` (#612)
authorYenForYang <YenForYang@users.noreply.github.com>
Tue, 14 Sep 2021 12:11:35 +0000 (07:11 -0500)
committerGitHub <noreply@github.com>
Tue, 14 Sep 2021 12:11:35 +0000 (22:11 +1000)
file.go

diff --git a/file.go b/file.go
index e2720e5a4d0886e0e75c620ac7187a7c8a037479..35fe9239aaaba3a0191d220f46d0e84fe79e1aa5 100644 (file)
--- a/file.go
+++ b/file.go
@@ -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()
 }