Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/prusa3d/PrusaSlicer.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLukáš Hejl <hejl.lukas@gmail.com>2021-09-14 12:09:23 +0300
committerLukáš Hejl <hejl.lukas@gmail.com>2021-09-14 12:09:43 +0300
commit1c6ecd9c1a7a4306895621e4e5712759a5a44c1c (patch)
tree664498070c4f3f470e1af4e0cfe1e6e8db59e887 /src/libslic3r
parent680a0665decd5a796211e0c6d185d48bbee96d3b (diff)
Replaced atof and atoi inside 3MF attribute parsing with fast_float::from_chars and boost::spirit that are faster.
Diffstat (limited to 'src/libslic3r')
-rw-r--r--src/libslic3r/Format/3mf.cpp15
1 files changed, 11 insertions, 4 deletions
diff --git a/src/libslic3r/Format/3mf.cpp b/src/libslic3r/Format/3mf.cpp
index 295c1413d..043f951ef 100644
--- a/src/libslic3r/Format/3mf.cpp
+++ b/src/libslic3r/Format/3mf.cpp
@@ -21,6 +21,7 @@
#include <boost/algorithm/string/replace.hpp>
#include <boost/filesystem/operations.hpp>
#include <boost/spirit/include/karma.hpp>
+#include <boost/spirit/include/qi_int.hpp>
#include <boost/log/trivial.hpp>
#include <boost/property_tree/ptree.hpp>
@@ -32,6 +33,8 @@ namespace pt = boost::property_tree;
#include <Eigen/Dense>
#include "miniz_extension.hpp"
+#include <fast_float/fast_float.h>
+
// Slightly faster than sprintf("%.9g"), but there is an issue with the karma floating point formatter,
// https://github.com/boostorg/spirit/pull/586
// where the exported string is one digit shorter than it should be to guarantee lossless round trip.
@@ -172,14 +175,18 @@ std::string get_attribute_value_string(const char** attributes, unsigned int att
float get_attribute_value_float(const char** attributes, unsigned int attributes_size, const char* attribute_key)
{
- const char* text = get_attribute_value_charptr(attributes, attributes_size, attribute_key);
- return (text != nullptr) ? (float)::atof(text) : 0.0f;
+ float value = 0.0f;
+ if (const char *text = get_attribute_value_charptr(attributes, attributes_size, attribute_key); text != nullptr)
+ fast_float::from_chars(text, text + strlen(text), value);
+ return value;
}
int get_attribute_value_int(const char** attributes, unsigned int attributes_size, const char* attribute_key)
{
- const char* text = get_attribute_value_charptr(attributes, attributes_size, attribute_key);
- return (text != nullptr) ? ::atoi(text) : 0;
+ int value = 0;
+ if (const char *text = get_attribute_value_charptr(attributes, attributes_size, attribute_key); text != nullptr)
+ boost::spirit::qi::parse(text, text + strlen(text), boost::spirit::qi::int_, value);
+ return value;
}
bool get_attribute_value_bool(const char** attributes, unsigned int attributes_size, const char* attribute_key)