diff --git a/include/nlohmann/detail/input/json_sax.hpp b/include/nlohmann/detail/input/json_sax.hpp index 684fac047..daad030ab 100644 --- a/include/nlohmann/detail/input/json_sax.hpp +++ b/include/nlohmann/detail/input/json_sax.hpp @@ -222,7 +222,9 @@ class json_sax_dom_parser bool string(string_t& val) { - handle_value(val); + // the interface allows moving the value (see json_sax::string), which + // hands the lexer's buffer to the new value instead of copying it + handle_value(std::move(val)); return true; } @@ -532,7 +534,8 @@ class json_sax_dom_callback_parser bool string(string_t& val) { - handle_value(val); + // see json_sax_dom_parser::string() + handle_value(std::move(val)); return true; } diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index b8da1e526..1a16ff705 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -10739,7 +10739,9 @@ class json_sax_dom_parser bool string(string_t& val) { - handle_value(val); + // the interface allows moving the value (see json_sax::string), which + // hands the lexer's buffer to the new value instead of copying it + handle_value(std::move(val)); return true; } @@ -11049,7 +11051,8 @@ class json_sax_dom_callback_parser bool string(string_t& val) { - handle_value(val); + // see json_sax_dom_parser::string() + handle_value(std::move(val)); return true; }