From 613d8b39e0d6e8af4b4aff5cffb639a7016c8f7c Mon Sep 17 00:00:00 2001 From: Travis Downs Date: Wed, 18 Dec 2024 17:31:48 -0300 Subject: [PATCH] json: add moving push to json_list When building up json lists in memory we have only the `push` method which takes const T&, but one taking an rvalue reference and moves into the list would be useful for heavy elements. --- include/seastar/json/json_elements.hh | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/include/seastar/json/json_elements.hh b/include/seastar/json/json_elements.hh index 90508f4f2e7..ff4a3e25c89 100644 --- a/include/seastar/json/json_elements.hh +++ b/include/seastar/json/json_elements.hh @@ -162,13 +162,22 @@ public: /** * Add an element to the list. - * @param element a new element that will be added to the list + * @param element a new element that will be added to the end of the list */ void push(const T& element) { _set = true; _elements.push_back(element); } + /** + * Move an element into the list. + * @param element a new element that will be added to the list using move-construction + */ + void push(T&& element) { + _set = true; + _elements.push_back(std::move(element)); + } + virtual std::string to_string() override { return formatter::to_json(_elements);