1
0
mirror of synced 2025-12-01 23:17:49 +03:00

Optimize ThreadPool and MatcherBase constructors (#2283)

Add a missing reserve and missing std::move to each ctor respectively. The latter should really be caught by a clang-tidy perf linter.
This commit is contained in:
Aaron Gokaslan
2025-11-30 18:49:23 -08:00
committed by GitHub
parent c1fa5e1710
commit 0a9102ff6b

View File

@@ -873,6 +873,7 @@ class ThreadPool final : public TaskQueue {
public: public:
explicit ThreadPool(size_t n, size_t mqr = 0) explicit ThreadPool(size_t n, size_t mqr = 0)
: shutdown_(false), max_queued_requests_(mqr) { : shutdown_(false), max_queued_requests_(mqr) {
threads_.reserve(n);
while (n) { while (n) {
threads_.emplace_back(worker(*this)); threads_.emplace_back(worker(*this));
n--; n--;
@@ -981,7 +982,7 @@ namespace detail {
class MatcherBase { class MatcherBase {
public: public:
MatcherBase(std::string pattern) : pattern_(pattern) {} MatcherBase(std::string pattern) : pattern_(std::move(pattern)) {}
virtual ~MatcherBase() = default; virtual ~MatcherBase() = default;
const std::string &pattern() const { return pattern_; } const std::string &pattern() const { return pattern_; }