From 914c8860e85520c001585d688548f7ee74d94162 Mon Sep 17 00:00:00 2001 From: Andrew Gasparovic <55992101+agasparovic-sabre@users.noreply.github.com> Date: Fri, 20 Mar 2020 15:46:34 -0700 Subject: [PATCH] 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. --- httplib.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/httplib.h b/httplib.h index 1e2ad17..6b5c1ca 100644 --- a/httplib.h +++ b/httplib.h @@ -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); }