Skip to content

Commit

Permalink
Re #8360. Use an std::vector rather than a C array.
Browse files Browse the repository at this point in the history
Doesn't leak like the old way did as it wasn't being cleaned up at all.
I'd be surprised if there's any significant impact on performance.
  • Loading branch information
RussellTaylor committed Mar 7, 2014
1 parent 1c2b5f2 commit 12f7152
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 16 deletions.
Expand Up @@ -60,7 +60,7 @@ class DLLExport MDPlaneImplicitFunction : public MDImplicitFunction
/// Create string for coordinate values.
std::string coordValue(const coord_t *arr) const;

coord_t *origin; ///< The origin point of the implicit plane.
std::vector<coord_t> origin; ///< The origin point of the implicit plane.
};

} // namespace Geometry
Expand Down
Expand Up @@ -17,7 +17,6 @@ namespace Geometry

MDPlaneImplicitFunction::MDPlaneImplicitFunction() : MDImplicitFunction()
{
this->origin = NULL;
}

/**
Expand All @@ -30,10 +29,9 @@ MDPlaneImplicitFunction::MDPlaneImplicitFunction() : MDImplicitFunction()
*/
MDPlaneImplicitFunction::MDPlaneImplicitFunction(const size_t nd,
const float *normal,
const float *point) :
MDImplicitFunction()
const float *point)
: MDImplicitFunction(), origin(nd)
{
this->origin = new coord_t[nd];
for( std::size_t i = 0; i < nd; i++)
{
this->origin[i] = static_cast<coord_t>(point[i]);
Expand All @@ -51,10 +49,9 @@ MDPlaneImplicitFunction::MDPlaneImplicitFunction(const size_t nd,
*/
MDPlaneImplicitFunction::MDPlaneImplicitFunction(const size_t nd,
const double *normal,
const double *point) :
MDImplicitFunction()
const double *point)
: MDImplicitFunction(), origin(nd)
{
this->origin = new coord_t[nd];
for( std::size_t i = 0; i < nd; i++)
{
this->origin[i] = static_cast<coord_t>(point[i]);
Expand Down Expand Up @@ -125,7 +122,7 @@ std::string MDPlaneImplicitFunction::toXMLString() const
origParameterElement->appendChild(origTypeElement);
AutoPtr<Element>origValueElement = pDoc->createElement("Value");
origParameterElement->appendChild(origValueElement);
AutoPtr<Text> origValueText = pDoc->createTextNode(this->coordValue(this->origin));
AutoPtr<Text> origValueText = pDoc->createTextNode(this->coordValue(this->origin.data()));
origValueElement->appendChild(origValueText);
origParameterElement->appendChild(origValueElement);

Expand Down Expand Up @@ -158,14 +155,9 @@ std::string MDPlaneImplicitFunction::coordValue(const coord_t *arr) const

void MDPlaneImplicitFunction::checkOrigin()
{
if (NULL == this->origin)
if ( origin.empty() )
{
std::size_t nd = this->getNumDims();
this->origin = new coord_t[nd];
for (std::size_t i = 0; i < nd; i++)
{
this->origin[i] = std::numeric_limits<coord_t>::quiet_NaN();
}
origin.resize(getNumDims(), std::numeric_limits<coord_t>::quiet_NaN());
}
}

Expand Down

0 comments on commit 12f7152

Please sign in to comment.