From 3f881de1c414cf14f8dc0ad5107562833d5616ad Mon Sep 17 00:00:00 2001 From: Aaron Gokaslan Date: Sun, 30 Nov 2025 15:47:47 -0500 Subject: [PATCH] Optimize ThreadPool and MatcherBase constructors Add a missing reserve and missing std::move to each ctor respectively. The latter should really be caught by a clang-tidy perf linter. --- httplib.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/httplib.h b/httplib.h index ed30e557a2..a235fd8ed4 100644 --- a/httplib.h +++ b/httplib.h @@ -873,6 +873,7 @@ class ThreadPool final : public TaskQueue { public: explicit ThreadPool(size_t n, size_t mqr = 0) : shutdown_(false), max_queued_requests_(mqr) { + threads_.reserve(n); while (n) { threads_.emplace_back(worker(*this)); n--; @@ -981,7 +982,7 @@ namespace detail { class MatcherBase { public: - MatcherBase(std::string pattern) : pattern_(pattern) {} + MatcherBase(std::string pattern) : pattern_(std::move(pattern)) {} virtual ~MatcherBase() = default; const std::string &pattern() const { return pattern_; }