diff --git a/include/nlohmann/detail/input/json_sax.hpp b/include/nlohmann/detail/input/json_sax.hpp index 684fac047..1627d2326 100644 --- a/include/nlohmann/detail/input/json_sax.hpp +++ b/include/nlohmann/detail/input/json_sax.hpp @@ -222,12 +222,16 @@ class json_sax_dom_parser bool string(string_t& val) { - handle_value(val); + // json_sax documents that the passed value may be moved from, + // so hand the buffer over instead of copying it + handle_value(std::move(val)); return true; } bool binary(binary_t& val) { + // json_sax documents that the passed value may be moved from, + // so hand the buffer over instead of copying it handle_value(std::move(val)); return true; } @@ -532,12 +536,16 @@ class json_sax_dom_callback_parser bool string(string_t& val) { - handle_value(val); + // json_sax documents that the passed value may be moved from, + // so hand the buffer over instead of copying it + handle_value(std::move(val)); return true; } bool binary(binary_t& val) { + // json_sax documents that the passed value may be moved from, + // so hand the buffer over instead of copying it handle_value(std::move(val)); return true; } diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index 890a7f721..e2c314c5f 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -10935,12 +10935,16 @@ class json_sax_dom_parser bool string(string_t& val) { - handle_value(val); + // json_sax documents that the passed value may be moved from, + // so hand the buffer over instead of copying it + handle_value(std::move(val)); return true; } bool binary(binary_t& val) { + // json_sax documents that the passed value may be moved from, + // so hand the buffer over instead of copying it handle_value(std::move(val)); return true; } @@ -11245,12 +11249,16 @@ class json_sax_dom_callback_parser bool string(string_t& val) { - handle_value(val); + // json_sax documents that the passed value may be moved from, + // so hand the buffer over instead of copying it + handle_value(std::move(val)); return true; } bool binary(binary_t& val) { + // json_sax documents that the passed value may be moved from, + // so hand the buffer over instead of copying it handle_value(std::move(val)); return true; }