Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Polygon constructor that avoids internal delete #359

Closed
wants to merge 2 commits into from

Conversation

pramsey
Copy link
Member

@pramsey pramsey commented Nov 30, 2020

The constructor that purely uses unique_ptr inputs seems to both avoid bulk copy and also the internal delete of the vector containing the rings. Failing that, a whole extra Polygon constructor will be needed.

LinearRing* nshell = dynamic_cast<LinearRing*>(shell);
if(! nshell) {
handle->ERROR_MESSAGE("Shell is not a LinearRing");
return NULL;
}
const GeometryFactory* gf = handle->geomFactory;

return gf->createPolygon(nshell, vholes.release());
/* Create unique_ptr version for constructor */
std::vector<std::unique_ptr<LinearRing>> vholes(nholes);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unless I'm wrong the current code will have vholes with nholes first elements at nullptr, followed by the content of tmpholes.
You'd probably want to do instead

Suggested change
std::vector<std::unique_ptr<LinearRing>> vholes(nholes);
std::vector<std::unique_ptr<LinearRing>> vholes;
vholes.reserve(nholes);

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep, you are right

@pramsey pramsey closed this Jan 4, 2021
@pramsey pramsey deleted the 3.8-poly-capi branch January 5, 2021 20:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants