Skip to content

Commit ffc294d

Browse files
authored
Reduce object copy (#1767)
1 parent fceada9 commit ffc294d

File tree

1 file changed

+20
-16
lines changed

1 file changed

+20
-16
lines changed

httplib.h

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2065,7 +2065,7 @@ void hosted_at(const std::string &hostname, std::vector<std::string> &addrs);
20652065

20662066
std::string append_query_params(const std::string &path, const Params &params);
20672067

2068-
std::pair<std::string, std::string> make_range_header(Ranges ranges);
2068+
std::pair<std::string, std::string> make_range_header(const Ranges &ranges);
20692069

20702070
std::pair<std::string, std::string>
20712071
make_basic_authentication_header(const std::string &username,
@@ -2571,7 +2571,7 @@ inline std::string trim_double_quotes_copy(const std::string &s) {
25712571

25722572
inline void split(const char *b, const char *e, char d,
25732573
std::function<void(const char *, const char *)> fn) {
2574-
return split(b, e, d, (std::numeric_limits<size_t>::max)(), fn);
2574+
return split(b, e, d, (std::numeric_limits<size_t>::max)(), std::move(fn));
25752575
}
25762576

25772577
inline void split(const char *b, const char *e, char d, size_t m,
@@ -5208,10 +5208,11 @@ inline std::string append_query_params(const std::string &path,
52085208
}
52095209

52105210
// Header utilities
5211-
inline std::pair<std::string, std::string> make_range_header(Ranges ranges) {
5211+
inline std::pair<std::string, std::string>
5212+
make_range_header(const Ranges &ranges) {
52125213
std::string field = "bytes=";
52135214
auto i = 0;
5214-
for (auto r : ranges) {
5215+
for (const auto &r : ranges) {
52155216
if (i != 0) { field += ", "; }
52165217
if (r.first != -1) { field += std::to_string(r.first); }
52175218
field += '-';
@@ -5364,7 +5365,7 @@ inline void Response::set_content_provider(
53645365
set_header("Content-Type", content_type);
53655366
content_length_ = in_length;
53665367
if (in_length > 0) { content_provider_ = std::move(provider); }
5367-
content_provider_resource_releaser_ = resource_releaser;
5368+
content_provider_resource_releaser_ = std::move(resource_releaser);
53685369
is_chunked_content_provider_ = false;
53695370
}
53705371

@@ -5374,7 +5375,7 @@ inline void Response::set_content_provider(
53745375
set_header("Content-Type", content_type);
53755376
content_length_ = 0;
53765377
content_provider_ = detail::ContentProviderAdapter(std::move(provider));
5377-
content_provider_resource_releaser_ = resource_releaser;
5378+
content_provider_resource_releaser_ = std::move(resource_releaser);
53785379
is_chunked_content_provider_ = false;
53795380
}
53805381

@@ -5384,7 +5385,7 @@ inline void Response::set_chunked_content_provider(
53845385
set_header("Content-Type", content_type);
53855386
content_length_ = 0;
53865387
content_provider_ = detail::ContentProviderAdapter(std::move(provider));
5387-
content_provider_resource_releaser_ = resource_releaser;
5388+
content_provider_resource_releaser_ = std::move(resource_releaser);
53885389
is_chunked_content_provider_ = true;
53895390
}
53905391

@@ -7612,14 +7613,15 @@ inline Result ClientImpl::Get(const std::string &path, const Params &params,
76127613
if (params.empty()) { return Get(path, headers); }
76137614

76147615
std::string path_with_query = append_query_params(path, params);
7615-
return Get(path_with_query, headers, progress);
7616+
return Get(path_with_query, headers, std::move(progress));
76167617
}
76177618

76187619
inline Result ClientImpl::Get(const std::string &path, const Params &params,
76197620
const Headers &headers,
76207621
ContentReceiver content_receiver,
76217622
Progress progress) {
7622-
return Get(path, params, headers, nullptr, content_receiver, progress);
7623+
return Get(path, params, headers, nullptr, std::move(content_receiver),
7624+
std::move(progress));
76237625
}
76247626

76257627
inline Result ClientImpl::Get(const std::string &path, const Params &params,
@@ -7628,12 +7630,13 @@ inline Result ClientImpl::Get(const std::string &path, const Params &params,
76287630
ContentReceiver content_receiver,
76297631
Progress progress) {
76307632
if (params.empty()) {
7631-
return Get(path, headers, response_handler, content_receiver, progress);
7633+
return Get(path, headers, std::move(response_handler),
7634+
std::move(content_receiver), std::move(progress));
76327635
}
76337636

76347637
std::string path_with_query = append_query_params(path, params);
7635-
return Get(path_with_query, headers, response_handler, content_receiver,
7636-
progress);
7638+
return Get(path_with_query, headers, std::move(response_handler),
7639+
std::move(content_receiver), std::move(progress));
76377640
}
76387641

76397642
inline Result ClientImpl::Head(const std::string &path) {
@@ -9008,19 +9011,20 @@ inline Result Client::Get(const std::string &path, const Headers &headers,
90089011
}
90099012
inline Result Client::Get(const std::string &path, const Params &params,
90109013
const Headers &headers, Progress progress) {
9011-
return cli_->Get(path, params, headers, progress);
9014+
return cli_->Get(path, params, headers, std::move(progress));
90129015
}
90139016
inline Result Client::Get(const std::string &path, const Params &params,
90149017
const Headers &headers,
90159018
ContentReceiver content_receiver, Progress progress) {
9016-
return cli_->Get(path, params, headers, content_receiver, progress);
9019+
return cli_->Get(path, params, headers, std::move(content_receiver),
9020+
std::move(progress));
90179021
}
90189022
inline Result Client::Get(const std::string &path, const Params &params,
90199023
const Headers &headers,
90209024
ResponseHandler response_handler,
90219025
ContentReceiver content_receiver, Progress progress) {
9022-
return cli_->Get(path, params, headers, response_handler, content_receiver,
9023-
progress);
9026+
return cli_->Get(path, params, headers, std::move(response_handler),
9027+
std::move(content_receiver), std::move(progress));
90249028
}
90259029

90269030
inline Result Client::Head(const std::string &path) { return cli_->Head(path); }

0 commit comments

Comments
 (0)