diff --git a/xs/src/ExPolygon.cpp b/xs/src/ExPolygon.cpp index 366b4de70..d2088d465 100644 --- a/xs/src/ExPolygon.cpp +++ b/xs/src/ExPolygon.cpp @@ -6,7 +6,8 @@ namespace Slic3r { ExPolygon::operator Polygons() const { - Polygons polygons(this->holes.size() + 1); + Polygons polygons; + polygons.reserve(this->holes.size() + 1); polygons.push_back(this->contour); for (Polygons::const_iterator it = this->holes.begin(); it != this->holes.end(); ++it) { polygons.push_back(*it); @@ -64,7 +65,7 @@ ExPolygon::is_valid() const bool ExPolygon::contains_line(const Line* line) const { - Polylines pl(1); + Polylines pl; pl.push_back(*line); Polylines pl_out; @@ -85,7 +86,8 @@ ExPolygon::contains_point(const Point* point) const Polygons ExPolygon::simplify_p(double tolerance) const { - Polygons pp(this->holes.size() + 1); + Polygons pp; + pp.reserve(this->holes.size() + 1); // contour Polygon p = this->contour; diff --git a/xs/src/Polyline.cpp b/xs/src/Polyline.cpp index dc05043ac..5f62b5b47 100644 --- a/xs/src/Polyline.cpp +++ b/xs/src/Polyline.cpp @@ -5,7 +5,7 @@ namespace Slic3r { Polyline::operator Polylines() const { - Polylines polylines(1); + Polylines polylines; polylines.push_back(*this); return polylines; } diff --git a/xs/src/Surface.cpp b/xs/src/Surface.cpp index 085756b86..e82cf8079 100644 --- a/xs/src/Surface.cpp +++ b/xs/src/Surface.cpp @@ -24,6 +24,15 @@ Surface::is_bridge() const } #ifdef SLIC3RXS +void +Surface::from_SV_check(SV* surface_sv) +{ + if (!sv_isa(surface_sv, "Slic3r::Surface") && !sv_isa(surface_sv, "Slic3r::Surface::Ref")) + CONFESS("Not a valid Slic3r::Surface object"); + // a XS Surface was supplied + *this = *(Surface *)SvIV((SV*)SvRV( surface_sv )); +} + SV* Surface::to_SV_ref() { SV* sv = newSV(0); diff --git a/xs/src/Surface.hpp b/xs/src/Surface.hpp index 304cc4572..cf89b1ac6 100644 --- a/xs/src/Surface.hpp +++ b/xs/src/Surface.hpp @@ -21,6 +21,7 @@ class Surface bool is_bridge() const; #ifdef SLIC3RXS + void from_SV_check(SV* surface_sv); SV* to_SV_ref(); SV* to_SV_clone_ref() const; #endif diff --git a/xs/xsp/SurfaceCollection.xsp b/xs/xsp/SurfaceCollection.xsp index 4219bbe65..6665a0a24 100644 --- a/xs/xsp/SurfaceCollection.xsp +++ b/xs/xsp/SurfaceCollection.xsp @@ -22,7 +22,7 @@ SurfaceCollection::new(...) RETVAL->surfaces.resize(items-1); for (unsigned int i = 1; i < items; i++) { // Note: a COPY of the input is stored - RETVAL->surfaces[i-1] = *(Surface *)SvIV((SV*)SvRV( ST(i) )); + RETVAL->surfaces[i-1].from_SV_check(ST(i)); } OUTPUT: RETVAL @@ -56,8 +56,9 @@ void SurfaceCollection::append(...) CODE: for (unsigned int i = 1; i < items; i++) { - // Note: a COPY of the input is stored - THIS->surfaces.push_back(*(Surface *)SvIV((SV*)SvRV( ST(i) ))); + Surface surface; + surface.from_SV_check( ST(i) ); + THIS->surfaces.push_back(surface); } void