From a93620621dd12354097ed4e646bdcd249e136630 Mon Sep 17 00:00:00 2001 From: Vojtech Bubnik Date: Thu, 18 Aug 2022 10:30:20 +0200 Subject: [PATCH] Performance improvement of GCodeProcessor: Replaced std::string with std::string_view for constant parameters Replaced boost:istarts_with() with boost::starts_with() --- src/libslic3r/GCode/GCodeProcessor.cpp | 9 +++++++-- src/slic3r/GUI/ImGuiWrapper.cpp | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/libslic3r/GCode/GCodeProcessor.cpp b/src/libslic3r/GCode/GCodeProcessor.cpp index 335a51696..e1341fa98 100644 --- a/src/libslic3r/GCode/GCodeProcessor.cpp +++ b/src/libslic3r/GCode/GCodeProcessor.cpp @@ -3779,8 +3779,13 @@ void GCodeProcessor::post_process() } auto process_used_filament = [&](std::string& gcode_line) { - auto process_tag = [](std::string& gcode_line, const std::string& tag, const std::vector& values) { - if (boost::algorithm::istarts_with(gcode_line, tag)) { + // Prefilter for parsing speed. + if (gcode_line.size() < 8 || gcode_line[0] != ';' || gcode_line[1] != ' ') + return false; + if (const char c = gcode_line[2]; c != 'f' && c != 't') + return false; + auto process_tag = [](std::string& gcode_line, const std::string_view tag, const std::vector& values) { + if (boost::algorithm::starts_with(gcode_line, tag)) { gcode_line = tag; char buf[1024]; for (size_t i = 0; i < values.size(); ++i) { diff --git a/src/slic3r/GUI/ImGuiWrapper.cpp b/src/slic3r/GUI/ImGuiWrapper.cpp index 6f83c5d7c..b5d5ad613 100644 --- a/src/slic3r/GUI/ImGuiWrapper.cpp +++ b/src/slic3r/GUI/ImGuiWrapper.cpp @@ -542,7 +542,7 @@ bool ImGuiWrapper::slider_float(const char* label, float* v, float v_min, float const float max_tooltip_width = ImGui::GetFontSize() * 20.0f; // let the label string start with "##" to hide the automatic label from ImGui::SliderFloat() - bool label_visible = !boost::algorithm::istarts_with(label, "##"); + bool label_visible = !boost::algorithm::starts_with(label, "##"); std::string str_label = label_visible ? std::string("##") + std::string(label) : std::string(label); // removes 2nd evenience of "##", if present