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 0ea3abd5e..deac3966e 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -10941,7 +10941,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; } @@ -11251,7 +11253,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; }