From 8a66829057e47cb6dd6ea5e00d7a097c9dd069a0 Mon Sep 17 00:00:00 2001 From: Povilas Kanapickas Date: Tue, 26 May 2020 01:13:20 +0300 Subject: [PATCH] genesys: Simplify access to nodes that are newly added to image pipeline --- backend/genesys/image_pipeline.h | 24 +++++++----------------- backend/genesys/low.cpp | 8 +++----- 2 files changed, 10 insertions(+), 22 deletions(-) diff --git a/backend/genesys/image_pipeline.h b/backend/genesys/image_pipeline.h index 0e3264a72..d4aef49e6 100644 --- a/backend/genesys/image_pipeline.h +++ b/backend/genesys/image_pipeline.h @@ -556,32 +556,22 @@ public: void clear(); template - void push_first_node(Args&&... args) - { - push_first_node(std::unique_ptr(new Node(std::forward(args)...))); - } - - template - void push_first_node(std::unique_ptr&& node) + Node& push_first_node(Args&&... args) { if (!nodes_.empty()) { throw SaneException("Trying to append first node when there are existing nodes"); } - nodes_.emplace_back(std::move(node)); + nodes_.emplace_back(std::unique_ptr(new Node(std::forward(args)...))); + return static_cast(*nodes_.back()); } template - void push_node(Args&&... args) + Node& push_node(Args&&... args) { ensure_node_exists(); - push_node(std::unique_ptr(new Node(*nodes_.back(), std::forward(args)...))); - } - - template - void push_node(std::unique_ptr&& node) - { - ensure_node_exists(); - nodes_.emplace_back(std::move(node)); + nodes_.emplace_back(std::unique_ptr(new Node(*nodes_.back(), + std::forward(args)...))); + return static_cast(*nodes_.back()); } bool get_next_row_data(std::uint8_t* out_data) diff --git a/backend/genesys/low.cpp b/backend/genesys/low.cpp index e4dec048c..564a0795a 100644 --- a/backend/genesys/low.cpp +++ b/backend/genesys/low.cpp @@ -915,11 +915,9 @@ ImagePipelineStack build_image_pipeline(const Genesys_Device& dev, const ScanSes // certain circumstances. buffer_size = align_multiple_ceil(buffer_size, 2); - auto node = std::unique_ptr( - new ImagePipelineNodeBufferedCallableSource( - width, lines, format, buffer_size, read_data_from_usb)); - node->set_last_read_multiple(2); - pipeline.push_first_node(std::move(node)); + auto& src_node = pipeline.push_first_node( + width, lines, format, buffer_size, read_data_from_usb); + src_node.set_last_read_multiple(2); if (log_image_data) { pipeline.push_node(debug_prefix + "_0_from_usb.tiff");