mirror of
https://github.com/yhirose/cpp-httplib
synced 2024-11-21 14:29:10 -07:00
Accept content by value to allow moving
Previously, calling set_content always resulted in 's' being copied. With this change, there will still be the same number of copies made (1) when doing `set_content(my_value, ...)`, but there will be no copies if a caller elects to do `set_content(std::move(value), ...)` or `set_content(some_function_that_returns_a_temporary(), ...)` instead.
This commit is contained in:
parent
dc6a72a0fd
commit
914c8860e8
1 changed files with 3 additions and 3 deletions
|
@ -313,7 +313,7 @@ struct Response {
|
|||
|
||||
void set_redirect(const char *url);
|
||||
void set_content(const char *s, size_t n, const char *content_type);
|
||||
void set_content(const std::string &s, const char *content_type);
|
||||
void set_content(std::string s, const char *content_type);
|
||||
|
||||
void set_content_provider(
|
||||
size_t length,
|
||||
|
@ -2736,9 +2736,9 @@ inline void Response::set_content(const char *s, size_t n,
|
|||
set_header("Content-Type", content_type);
|
||||
}
|
||||
|
||||
inline void Response::set_content(const std::string &s,
|
||||
inline void Response::set_content(std::string s,
|
||||
const char *content_type) {
|
||||
body = s;
|
||||
body = std::move(s);
|
||||
set_header("Content-Type", content_type);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue