From c11948a084559d1e9dd3a6eedf71521f0e555d5f Mon Sep 17 00:00:00 2001 From: Vojtech Bubnik Date: Tue, 1 Mar 2022 16:41:52 +0100 Subject: [PATCH] FontItem improvmement: Use default constructors to let the compiler generate move constructor and move assignement. Also used some move operators to reduce unnecessary memory allocations. Cherry picked commit: 120a85d4c4b90ffafced442ee5e63e5f794f6945 --- src/libslic3r/Emboss.cpp | 6 +++--- src/libslic3r/Format/3mf.cpp | 4 ++-- src/libslic3r/TextConfiguration.hpp | 11 +---------- src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp | 2 +- src/slic3r/Utils/FontListSerializable.cpp | 2 +- src/slic3r/Utils/WxFontUtils.cpp | 2 +- 6 files changed, 9 insertions(+), 18 deletions(-) diff --git a/src/libslic3r/Emboss.cpp b/src/libslic3r/Emboss.cpp index 4f8aba9f6..98032c477 100644 --- a/src/libslic3r/Emboss.cpp +++ b/src/libslic3r/Emboss.cpp @@ -184,9 +184,9 @@ std::optional Private::get_glyph( } FontItem Private::create_font_item(std::wstring name, std::wstring path) { - return FontItem(boost::nowide::narrow(name.c_str()), - boost::nowide::narrow(path.c_str()), - FontItem::Type::file_path, FontProp()); + return { boost::nowide::narrow(name.c_str()), + boost::nowide::narrow(path.c_str()), + FontItem::Type::file_path, FontProp() }; } ExPolygons Private::dilate_to_unique_points(ExPolygons &expolygons) diff --git a/src/libslic3r/Format/3mf.cpp b/src/libslic3r/Format/3mf.cpp index 037108114..74c3880cf 100644 --- a/src/libslic3r/Format/3mf.cpp +++ b/src/libslic3r/Format/3mf.cpp @@ -3395,10 +3395,10 @@ std::optional TextConfigurationSerialization::read(const char std::string font_descriptor = get_attribute_value_string(attributes, num_attributes, FONT_DESCRIPTOR_ATTR); std::string type_str = get_attribute_value_string(attributes, num_attributes, FONT_DESCRIPTOR_TYPE_ATTR); FontItem::Type type = TextConfigurationSerialization::get_type(type_str); - FontItem fi(style_name, font_descriptor, type, fp); + FontItem fi{ style_name, std::move(font_descriptor), type, std::move(fp) }; std::string text = get_attribute_value_string(attributes, num_attributes, TEXT_DATA_ATTR); - return TextConfiguration(fi, text); + return TextConfiguration(std::move(fi), std::move(text)); } diff --git a/src/libslic3r/TextConfiguration.hpp b/src/libslic3r/TextConfiguration.hpp index 98822e639..2a18aaff3 100644 --- a/src/libslic3r/TextConfiguration.hpp +++ b/src/libslic3r/TextConfiguration.hpp @@ -122,22 +122,13 @@ struct FontItem enum class Type; // Define what is stored in path - Type type; + Type type { Type::undefined }; // User modification of font style FontProp prop; - FontItem() : type(Type::undefined){} // set undefined type - // when name is empty than Font item was loaded from .3mf file // and potentionaly it is not reproducable - FontItem(const std::string &name, - const std::string &path, - Type type, - const FontProp & prop) - : name(name), path(path), type(type), prop(prop) // copy values - {} - // define data stored in path // when wx change way of storing add new descriptor Type enum class Type { diff --git a/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp b/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp index c870a0bc1..784425253 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp @@ -1912,7 +1912,7 @@ bool GLGizmoEmboss::choose_true_type_file() std::string name = get_file_name(path); //make_unique_name(name, m_font_list); const FontProp& prop = m_font_manager.get_font_prop(); - FontItem fi(name, path, FontItem::Type::file_path, prop); + FontItem fi{ name, path, FontItem::Type::file_path, prop }; m_font_manager.add_font(fi); // set first valid added font as active if (m_font_manager.load_font(index)) return true; diff --git a/src/slic3r/Utils/FontListSerializable.cpp b/src/slic3r/Utils/FontListSerializable.cpp index 802cc2185..2203339f6 100644 --- a/src/slic3r/Utils/FontListSerializable.cpp +++ b/src/slic3r/Utils/FontListSerializable.cpp @@ -101,7 +101,7 @@ std::optional FontListSerializable::load_font_item( read(app_cfg_section, APP_CONFIG_FONT_LINE_GAP, fp.line_gap); FontItem::Type type = WxFontUtils::get_actual_type(); - return FontItem(name, path, type, fp); + return FontItem{ name, path, type, fp }; } void FontListSerializable::store_font_item(AppConfig & cfg, diff --git a/src/slic3r/Utils/WxFontUtils.cpp b/src/slic3r/Utils/WxFontUtils.cpp index 3e36b45f4..ad143b4de 100644 --- a/src/slic3r/Utils/WxFontUtils.cpp +++ b/src/slic3r/Utils/WxFontUtils.cpp @@ -121,7 +121,7 @@ FontItem WxFontUtils::get_font_item(const wxFont &font, const std::string& name) // synchronize font property with actual font FontProp font_prop; WxFontUtils::update_property(font_prop, font); - return FontItem(name_item, fontDesc, type, font_prop); + return { name_item, fontDesc, type, font_prop }; } FontItem WxFontUtils::get_os_font()