Skip to content

Commit

Permalink
refactor: prevent extra move for get-methods with nrvo (#73)
Browse files Browse the repository at this point in the history
* removed extra move with using nrvo
* fix build issue
  • Loading branch information
jirol9xa authored Nov 26, 2024
1 parent b5e9e99 commit bc10764
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions include/thread_pool/thread_safe_queue.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ namespace dp {
std::scoped_lock lock(mutex_);
if (data_.empty()) return std::nullopt;

auto front = std::move(data_.front());
std::optional<T> front = std::move(data_.front());
data_.pop_front();
return front;
}
Expand All @@ -65,7 +65,7 @@ namespace dp {
std::scoped_lock lock(mutex_);
if (data_.empty()) return std::nullopt;

auto back = std::move(data_.back());
std::optional<T> back = std::move(data_.back());
data_.pop_back();
return back;
}
Expand All @@ -74,7 +74,7 @@ namespace dp {
std::scoped_lock lock(mutex_);
if (data_.empty()) return std::nullopt;

auto back = std::move(data_.back());
std::optional<T> back = std::move(data_.back());
data_.pop_back();
return back;
}
Expand All @@ -95,10 +95,10 @@ namespace dp {

if (data_.empty()) return std::nullopt;

auto front = data_.front();
std::optional<T> front = data_.front();
data_.pop_front();

data_.push_back(front);
data_.push_back(*front);

return front;
}
Expand Down

0 comments on commit bc10764

Please sign in to comment.