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

More cleanups and simplification #428

Merged
merged 17 commits into from Aug 20, 2019
Merged

Conversation

rpavlik
Copy link
Contributor

@rpavlik rpavlik commented May 23, 2019

This mostly cleans up the remaining pieces I had in flight, plus some extra cleanups. tests pass, the containers aren't very different (still allocated the same), but this lets the "port" to backing by std::vector be fairly simple in addition to making things cleaner and more uniform.

@rpavlik
Copy link
Contributor Author

rpavlik commented May 23, 2019

Apparently the windows toolchain is too old to deal with defaulting move constructors, etc. Fortunately, this is apparently not necessary anymore, so I just dropped those patches from the series.

@rpavlik
Copy link
Contributor Author

rpavlik commented May 23, 2019

Ah ha! I took a different approach to doing the IdListAdditions thing and added a MergeInto method. This let me get rid of nearly all remaining non-range-for over IdLists. See last two commits in https://github.com/rpavlik/solvespace/commits/idlist-merge

@whitequark
Copy link
Contributor

That's definitely one way to do it, yup.

@rpavlik
Copy link
Contributor Author

rpavlik commented May 28, 2019

OK, this has been rebased and squashed into fewer commits with better messages. I've also included the MergeInto work on IdList, and tweaked the "get rid of qsort" commit to use lambdas for simplicity.

This removes nearly all non-range-for loops over containers, at least those that I had detected when I first marked them with comments a year ago. It also addresses the underlying reasons why some couldn't be ported to range-for, such as addition-during-iteration. The other changes are rather standalone - think you can mostly drop any ones you don't care for in the series.

The underlying motivation behind these changes is either performance (for those that originated long ago), or improved software structure (for newer ones) - many of these issues were noticed when I attempted to port these containers to being based on std::vector or something else, but the fixes didn't depend on such a port.

@rpavlik rpavlik force-pushed the simplify6 branch 2 times, most recently from 6e97784 to 3c4c7cb Compare May 28, 2019 18:46
@rpavlik
Copy link
Contributor Author

rpavlik commented May 28, 2019

OK, undoing the merge-idlists commit because it apparently is resulting in benchmark issues locally?

@whitequark
Copy link
Contributor

Thanks for the update! I didn't forget about this PR, was just a bit busy with other projects.

@rpavlik rpavlik mentioned this pull request Jul 9, 2019
@rpavlik
Copy link
Contributor Author

rpavlik commented Jul 9, 2019

np - I just poked at this again to verify a vscode bug had been fixed, and one thing led to another ;)

@whitequark
Copy link
Contributor

@rpavlik I just reviewed all these changes. I am quite happy with how they are. Could you do a rebase and then I'll merge it?

rpavlik and others added 10 commits August 20, 2019 10:17
Also add comments about indexing and when we don't use range-for.
Allows forcing const iteration.
Removes consuming code from the implementation details, easing swap of
the underlying container, etc.
Clearer and less error-prone to use standard-supplied algorithms.
Offloads most of the work onto standard algorithms to make it
more self-evidently correct.
Pointing out one potential issue with an assert.
Changes resemble those already made to IdList.
Removes static variable usage, permits hiding of the underlying pointer
(std::sort uses iterators intead), type safety, etc.
@rpavlik
Copy link
Contributor Author

rpavlik commented Aug 20, 2019

oh this is a fun rebase - forgot that I did the "remove all the .v" on a separate branch :) Almost done.

@whitequark
Copy link
Contributor

(This is still a lot of churn, but it is churn I was prepared to apply anyway, and I am convinced that SolveSpace urgently needs to be modernized if we are to seek healthy external contributors. The current situation where anyone has to learn the unconventional data structures first to do anything is not really sustainable...)

Allows distancing users from the internal "elem" member.

Add Get() and operator[].
Replace direct references to elem.
Make elem and elemsAllocated private in IdList/List.
std::swap is an idiomatic way to do a move.
Was getting segfaults near here with another patch since removed from the branch.
Moving these assignments after the memfree means they still have
useful data when debugging a crash in memfree.
Counterpart of First().  standard library calls this "back()".
This broke encapsulation and thus caused problems for any deeper changes
to List.
@rpavlik
Copy link
Contributor Author

rpavlik commented Aug 20, 2019

OK, rebase complete! Thanks for the review!

@whitequark whitequark merged commit b284e80 into solvespace:master Aug 20, 2019
@rpavlik rpavlik deleted the simplify6 branch August 20, 2019 21:16
@whitequark
Copy link
Contributor

You've made some excellent contributions to SolveSpace, and as such I've invited you to the SolveSpace organization. For now I would still like all non-trivial changes go through pre-commit code review, but feel free to commit trivial ones directly (typos, broken build, etc.)

@rpavlik
Copy link
Contributor Author

rpavlik commented Aug 20, 2019

Thanks, and thanks for your excellent and prompt reviewing - if only I was as prompt on my PR reviews :)

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