Skip to content

Commit 914c886

Browse files
agasparovic-sabreyhirose
authored andcommitted
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.
1 parent dc6a72a commit 914c886

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

httplib.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ struct Response {
313313

314314
void set_redirect(const char *url);
315315
void set_content(const char *s, size_t n, const char *content_type);
316-
void set_content(const std::string &s, const char *content_type);
316+
void set_content(std::string s, const char *content_type);
317317

318318
void set_content_provider(
319319
size_t length,
@@ -2736,9 +2736,9 @@ inline void Response::set_content(const char *s, size_t n,
27362736
set_header("Content-Type", content_type);
27372737
}
27382738

2739-
inline void Response::set_content(const std::string &s,
2739+
inline void Response::set_content(std::string s,
27402740
const char *content_type) {
2741-
body = s;
2741+
body = std::move(s);
27422742
set_header("Content-Type", content_type);
27432743
}
27442744

0 commit comments

Comments
 (0)