-
Notifications
You must be signed in to change notification settings - Fork 511
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
Conversation
updated to fix a style issue. |
There was a problem hiding this 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.
@@ -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. |
There was a problem hiding this comment.
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...
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.)
There was a problem hiding this comment.
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.
Cool, thanks. Will rebase with the changes suggested. |
Also add comments about indexing and when we don't use range-for.
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) { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
Merged f7f0a93, adding a similar assert for SMesh as well. |
Closing since most of this got in |
I actually very much want for loops, that will enable some IdList optimizations, see #430. |
Ah, you've opened #428. Sorry for the noise. |
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.)