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

Hopefully-Uncontroversial cleanups #413

Closed
wants to merge 3 commits into from

Conversation

rpavlik
Copy link
Contributor

@rpavlik rpavlik commented May 20, 2019

Went through my old branches and pulled out the commits that look reasonably safe and innocuous. (My switch to use std::vector inexplicably is causing test failures, and my performance improvement to bulk-add to non-vector collections is not very pretty.)

All tests pass on Debian Buster. Feel free to cherry-pick if some of them don't appeal to you - they're mostly independent or in brief sequences (e.g. the CountIf and GetNumConstraints changes are related, the WRAP changes are related, the rest are pretty independent though I don't know what would happen if you re-ordered the "convert to range-for" commits.)

@rpavlik
Copy link
Contributor Author

rpavlik commented May 20, 2019

updated to fix a style issue.

Copy link
Contributor

@whitequark whitequark left a comment

Choose a reason for hiding this comment

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

Thanks. I've wanted to make some of these changes myself for similar reasons but never got around to it, so I'm definitely interested in this patchset.

src/mesh.cpp Outdated Show resolved Hide resolved
@@ -425,6 +425,7 @@ void Group::Generate(IdList<Entity,hEntity> *entity,
// Get some arbitrary point in the sketch, that will be used
// as a reference when defining top and bottom faces.
hEntity pt = { 0 };
// Not using range-for here because we're changing the size of entity in the loop.
Copy link
Contributor

Choose a reason for hiding this comment

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

Oh of course that's why my own range-for patch (in a local branch that got buried years ago) didn't work. Iterator invalidation, the second worst thing in C++ that "modern" C++ does absolutely nothing to help with...

Copy link
Contributor

Choose a reason for hiding this comment

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

Can we add iterators that don't get invalidated when inserting into the collection, maybe? Store an index as well as pointer to the element.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

maybe as "future work". I did have some patches that make an IdListAdditions type, which basically queues up things to add so it can be bulk-added at the end via a merge. Would also avoid invalidating iterators if iterating an idlist, but not sure the clarity tradeoff is worth it. (I reverted the patch on my dev branch after doing the port to std::vector as a backend, since that gave the equivalent performance improvement. Think it was allocation behavior that was gettting me.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here's that branch rebased on this, and trimmed. https://github.com/rpavlik/solvespace/commits/idlist-additions

See in particular this: rpavlik@93f5e41 I only did this in the few places where I saw it coming up a lot on profiling data, but I think this could be used to avoid iterator invalidation in loops as well - instead of adding directly, add to an "additions" object, then "MoveIntoList" after iteration is complete.

src/undoredo.cpp Outdated Show resolved Hide resolved
@whitequark
Copy link
Contributor

I've merged about half of the commits as f885daf, 43c9cba and 39c3480.

I'd like to merge the range-for stuff but I think we need to do something about iterator invalidation while adding to the collection.

@rpavlik
Copy link
Contributor Author

rpavlik commented May 22, 2019

Cool, thanks. Will rebase with the changes suggested.

@rpavlik
Copy link
Contributor Author

rpavlik commented May 22, 2019

OK, rebased the remaining changes, tried to make my commit messages more like yours and combine some commits.

@@ -92,10 +92,11 @@ __attribute__((__format__ (__printf__, 1, 2)))
#endif
std::string ssprintf(const char *fmt, ...);

inline int WRAP(int v, int n) {
template<typename T>
inline T WRAP(T v, T n) {
Copy link
Contributor

Choose a reason for hiding this comment

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

(I think you missed my earlier question.) I don't understand this change--what's the point of making WRAP generic if it's only used with ints anyway and you need to cast it each time?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, I did miss your question. To be honest, I have no idea, that's the risk of me leaving commits un-submitted for so long.

@whitequark
Copy link
Contributor

Merged f7f0a93, adding a similar assert for SMesh as well.

@rpavlik
Copy link
Contributor Author

rpavlik commented May 23, 2019

Closing since most of this got in

@rpavlik rpavlik closed this May 23, 2019
@whitequark
Copy link
Contributor

I actually very much want for loops, that will enable some IdList optimizations, see #430.

@whitequark whitequark reopened this May 23, 2019
@whitequark
Copy link
Contributor

Ah, you've opened #428. Sorry for the noise.

@whitequark whitequark closed this May 23, 2019
@rpavlik rpavlik deleted the uncontroversial branch May 23, 2019 21:10
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.

None yet

2 participants