From d9ea1a4b2481b347ee5ea953dff61f9abed282c3 Mon Sep 17 00:00:00 2001 From: "xun.zhang" Date: Sun, 29 Sep 2024 16:13:51 +0800 Subject: [PATCH] FIX: performance issue caused by copy LayerResult jira:NONE Signed-off-by: xun.zhang Change-Id: I5f1bda598ef096999a0eda2fa68d2a24c97c22ca --- src/libslic3r/GCode.cpp | 5 ++++- src/libslic3r/GCode.hpp | 25 +++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/libslic3r/GCode.cpp b/src/libslic3r/GCode.cpp index 4d0ed1f7f..81ff2aca4 100644 --- a/src/libslic3r/GCode.cpp +++ b/src/libslic3r/GCode.cpp @@ -2528,7 +2528,10 @@ void GCode::process_layers( //BBS check_placeholder_parser_failed(); print.throw_if_canceled(); - return this->process_layer(print, layer.second, layer_tools, &layer == &layers_to_print.back(), &print_object_instances_ordering, size_t(-1)); + GCode::LayerResult res = this->process_layer(print, layer.second, layer_tools, &layer == &layers_to_print.back(), &print_object_instances_ordering, size_t(-1)); + res.gcode_store_pos = layer_to_print_idx - 1; + layers_results[layer_to_print_idx - 1] = std::move(res); + return layers_results[layer_to_print_idx - 1]; } }); if (m_spiral_vase) { diff --git a/src/libslic3r/GCode.hpp b/src/libslic3r/GCode.hpp index 05cd8ecd7..0127b607c 100644 --- a/src/libslic3r/GCode.hpp +++ b/src/libslic3r/GCode.hpp @@ -296,6 +296,31 @@ private: bool spiral_vase_enable { false }; // Should the cooling buffer content be flushed at the end of this layer? bool cooling_buffer_flush { false }; + // the layer store pos of gcode + size_t gcode_store_pos; + LayerResult() = default; + LayerResult(const std::string& gcode_, const size_t layer_id_, const bool spiral_vase_enable_, const bool cooling_buffer_flush_, const size_t gcode_store_pos_ = static_cast(-1)) : + gcode(gcode_), layer_id(layer_id_), spiral_vase_enable(spiral_vase_enable_), cooling_buffer_flush(cooling_buffer_flush_), gcode_store_pos(gcode_store_pos_){} + LayerResult(const LayerResult& other) = default; + LayerResult& operator=(const LayerResult& other) = default; + LayerResult(LayerResult&& other) noexcept { + gcode = std::move(other.gcode); + layer_id = other.layer_id; + spiral_vase_enable = other.spiral_vase_enable; + cooling_buffer_flush = other.cooling_buffer_flush; + gcode_store_pos = other.gcode_store_pos; + } + + LayerResult& operator=(LayerResult&& other) noexcept { + if (this != &other) { + gcode = std::move(other.gcode); + layer_id = other.layer_id; + spiral_vase_enable = other.spiral_vase_enable; + cooling_buffer_flush = other.cooling_buffer_flush; + gcode_store_pos = other.gcode_store_pos; + } + return *this; + } }; LayerResult process_layer( const Print &print,