Skip to content

Commit 0a9102f

Browse files
authored
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.
1 parent c1fa5e1 commit 0a9102f

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

httplib.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -873,6 +873,7 @@ class ThreadPool final : public TaskQueue {
873873
public:
874874
explicit ThreadPool(size_t n, size_t mqr = 0)
875875
: shutdown_(false), max_queued_requests_(mqr) {
876+
threads_.reserve(n);
876877
while (n) {
877878
threads_.emplace_back(worker(*this));
878879
n--;
@@ -981,7 +982,7 @@ namespace detail {
981982

982983
class MatcherBase {
983984
public:
984-
MatcherBase(std::string pattern) : pattern_(pattern) {}
985+
MatcherBase(std::string pattern) : pattern_(std::move(pattern)) {}
985986
virtual ~MatcherBase() = default;
986987

987988
const std::string &pattern() const { return pattern_; }

0 commit comments

Comments
 (0)