From 52e8c82999cd265fee14ed1cfc9e96b931d03654 Mon Sep 17 00:00:00 2001 From: YenForYang Date: Mon, 13 Sep 2021 06:17:54 -0500 Subject: [PATCH] Inlineable methods to access File piecePriority (#601) --- file.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/file.go b/file.go index bd5a6999..e2720e5a 100644 --- a/file.go +++ b/file.go @@ -146,19 +146,19 @@ func (f *File) NewReader() Reader { // Sets the minimum priority for pieces in the File. func (f *File) SetPriority(prio piecePriority) { f.t.cl.lock() - defer f.t.cl.unlock() - if prio == f.prio { - return + if prio != f.prio { + f.prio = prio + f.t.updatePiecePriorities(f.firstPieceIndex(), f.endPieceIndex()) } - f.prio = prio - f.t.updatePiecePriorities(f.firstPieceIndex(), f.endPieceIndex()) + f.t.cl.unlock() } // Returns the priority per File.SetPriority. -func (f *File) Priority() piecePriority { +func (f *File) Priority() (prio piecePriority) { f.t.cl.lock() - defer f.t.cl.unlock() - return f.prio + prio = f.prio + f.t.cl.unlock() + return } // Returns the index of the first piece containing data for the file. -- 2.48.1