mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-09-27 19:01:02 +00:00
Move polygons instead of copying them on move
MultiPoint had no rvalue constructor, so the derived move constructors bound to the const reference and copied; append reserved exactly, so collecting pieces one by one was quadratic. Colour segmentation ~3 s at 0.1 mm / 2000k, was ~40, and ordinary prints gain too.
This commit is contained in:
@@ -19,11 +19,13 @@ public:
|
|||||||
|
|
||||||
MultiPoint() {}
|
MultiPoint() {}
|
||||||
MultiPoint(const MultiPoint &other) : points(other.points) {}
|
MultiPoint(const MultiPoint &other) : points(other.points) {}
|
||||||
MultiPoint(MultiPoint &&other) : points(std::move(other.points)) {}
|
MultiPoint(MultiPoint &&other) noexcept : points(std::move(other.points)) {}
|
||||||
MultiPoint(std::initializer_list<Point> list) : points(list) {}
|
MultiPoint(std::initializer_list<Point> list) : points(list) {}
|
||||||
explicit MultiPoint(const Points &_points) : points(_points) {}
|
explicit MultiPoint(const Points &_points) : points(_points) {}
|
||||||
|
// Without it, the derived classes' move constructors passing std::move(points) here copied them.
|
||||||
|
explicit MultiPoint(Points &&_points) noexcept : points(std::move(_points)) {}
|
||||||
MultiPoint& operator=(const MultiPoint &other) { points = other.points; return *this; }
|
MultiPoint& operator=(const MultiPoint &other) { points = other.points; return *this; }
|
||||||
MultiPoint& operator=(MultiPoint &&other) { points = std::move(other.points); return *this; }
|
MultiPoint& operator=(MultiPoint &&other) noexcept { points = std::move(other.points); return *this; }
|
||||||
virtual ~MultiPoint() = default;
|
virtual ~MultiPoint() = default;
|
||||||
void scale(double factor);
|
void scale(double factor);
|
||||||
void scale(double factor_x, double factor_y);
|
void scale(double factor_x, double factor_y);
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ public:
|
|||||||
explicit Polygon(const Points &points) : MultiPoint(points) {}
|
explicit Polygon(const Points &points) : MultiPoint(points) {}
|
||||||
Polygon(std::initializer_list<Point> points) : MultiPoint(points) {}
|
Polygon(std::initializer_list<Point> points) : MultiPoint(points) {}
|
||||||
Polygon(const Polygon &other) : MultiPoint(other.points) {}
|
Polygon(const Polygon &other) : MultiPoint(other.points) {}
|
||||||
Polygon(Polygon &&other) : MultiPoint(std::move(other.points)) {}
|
Polygon(Polygon &&other) noexcept : MultiPoint(std::move(other.points)) {}
|
||||||
static Polygon new_scale(const std::vector<Vec2d> &points) {
|
static Polygon new_scale(const std::vector<Vec2d> &points) {
|
||||||
Polygon pgn;
|
Polygon pgn;
|
||||||
pgn.points.reserve(points.size());
|
pgn.points.reserve(points.size());
|
||||||
@@ -36,7 +36,7 @@ public:
|
|||||||
return pgn;
|
return pgn;
|
||||||
}
|
}
|
||||||
Polygon& operator=(const Polygon &other) { points = other.points; return *this; }
|
Polygon& operator=(const Polygon &other) { points = other.points; return *this; }
|
||||||
Polygon& operator=(Polygon &&other) { points = std::move(other.points); return *this; }
|
Polygon& operator=(Polygon &&other) noexcept { points = std::move(other.points); return *this; }
|
||||||
|
|
||||||
Point& operator[](Points::size_type idx) { return this->points[idx]; }
|
Point& operator[](Points::size_type idx) { return this->points[idx]; }
|
||||||
const Point& operator[](Points::size_type idx) const { return this->points[idx]; }
|
const Point& operator[](Points::size_type idx) const { return this->points[idx]; }
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ class Polyline : public MultiPoint {
|
|||||||
public:
|
public:
|
||||||
Polyline() {};
|
Polyline() {};
|
||||||
Polyline(const Polyline& other) : MultiPoint(other.points), fitting_result(other.fitting_result) {}
|
Polyline(const Polyline& other) : MultiPoint(other.points), fitting_result(other.fitting_result) {}
|
||||||
Polyline(Polyline &&other) : MultiPoint(std::move(other.points)), fitting_result(std::move(other.fitting_result)) {}
|
Polyline(Polyline &&other) noexcept : MultiPoint(std::move(other.points)), fitting_result(std::move(other.fitting_result)) {}
|
||||||
Polyline(std::initializer_list<Point> list) : MultiPoint(list) {
|
Polyline(std::initializer_list<Point> list) : MultiPoint(list) {
|
||||||
fitting_result.clear();
|
fitting_result.clear();
|
||||||
}
|
}
|
||||||
@@ -41,7 +41,7 @@ public:
|
|||||||
fitting_result = other.fitting_result;
|
fitting_result = other.fitting_result;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
Polyline& operator=(Polyline&& other) {
|
Polyline& operator=(Polyline&& other) noexcept {
|
||||||
points = std::move(other.points);
|
points = std::move(other.points);
|
||||||
fitting_result = std::move(other.fitting_result);
|
fitting_result = std::move(other.fitting_result);
|
||||||
return *this;
|
return *this;
|
||||||
|
|||||||
@@ -929,9 +929,9 @@ public:
|
|||||||
::fread(&y, sizeof(coord_t), 1, file);
|
::fread(&y, sizeof(coord_t), 1, file);
|
||||||
poly.points.emplace_back(Point(x * scale, y * scale));
|
poly.points.emplace_back(Point(x * scale, y * scale));
|
||||||
}
|
}
|
||||||
|
printf("Polygon %d, area: %lf\n", i, area(poly.points));
|
||||||
if (which == -1 || which == i)
|
if (which == -1 || which == i)
|
||||||
m_support_polygons_deserialized.emplace_back(std::move(poly));
|
m_support_polygons_deserialized.emplace_back(std::move(poly));
|
||||||
printf("Polygon %d, area: %lf\n", i, area(poly.points));
|
|
||||||
}
|
}
|
||||||
::fread(&n_polygons, 4, 1, file);
|
::fread(&n_polygons, 4, 1, file);
|
||||||
m_trimming_polygons_deserialized.reserve(n_polygons);
|
m_trimming_polygons_deserialized.reserve(n_polygons);
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ public:
|
|||||||
thickness(other.thickness), thickness_layers(other.thickness_layers),
|
thickness(other.thickness), thickness_layers(other.thickness_layers),
|
||||||
bridge_angle(other.bridge_angle), extra_perimeters(other.extra_perimeters)
|
bridge_angle(other.bridge_angle), extra_perimeters(other.extra_perimeters)
|
||||||
{};
|
{};
|
||||||
Surface(Surface &&rhs)
|
Surface(Surface &&rhs) noexcept
|
||||||
: surface_type(rhs.surface_type), expolygon(std::move(rhs.expolygon)),
|
: surface_type(rhs.surface_type), expolygon(std::move(rhs.expolygon)),
|
||||||
thickness(rhs.thickness), thickness_layers(rhs.thickness_layers),
|
thickness(rhs.thickness), thickness_layers(rhs.thickness_layers),
|
||||||
bridge_angle(rhs.bridge_angle), extra_perimeters(rhs.extra_perimeters)
|
bridge_angle(rhs.bridge_angle), extra_perimeters(rhs.extra_perimeters)
|
||||||
@@ -87,7 +87,7 @@ public:
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
Surface& operator=(Surface &&rhs)
|
Surface& operator=(Surface &&rhs) noexcept
|
||||||
{
|
{
|
||||||
surface_type = rhs.surface_type;
|
surface_type = rhs.surface_type;
|
||||||
expolygon = std::move(rhs.expolygon);
|
expolygon = std::move(rhs.expolygon);
|
||||||
|
|||||||
@@ -162,10 +162,10 @@ inline void append(std::vector<T, Alloc> &dest, std::vector<T, Alloc> &&src)
|
|||||||
{
|
{
|
||||||
if (dest.empty())
|
if (dest.empty())
|
||||||
dest = std::move(src);
|
dest = std::move(src);
|
||||||
else {
|
else
|
||||||
dest.reserve(dest.size() + src.size());
|
// insert() grows the capacity geometrically; reserving exactly the new size reallocated on every call, which
|
||||||
std::move(std::begin(src), std::end(src), std::back_inserter(dest));
|
// made appending piece by piece quadratic.
|
||||||
}
|
dest.insert(dest.end(), std::make_move_iterator(src.begin()), std::make_move_iterator(src.end()));
|
||||||
src.clear();
|
src.clear();
|
||||||
src.shrink_to_fit();
|
src.shrink_to_fit();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user