-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
[C++] Optimizations and cleanups and const correctness, oh my #3478
Conversation
Passing a shared_ptr as const ref is not a good idea. I had a discussion on Stackoverflow 5 years ago, exactly because I was thinking about doing that. You are killing the shared_ptr promise to ensure a pointer is valid as long as at least one place in code holds the shared_ptr. If you really want to improve that (what I had in mind since I wrote that code) is to pass through raw pointers and make sure there's "one source of truth" that owns the pointer (using a unique_ptr then). |
I think I switched most to be pass by value, which avoids incrementing and decrementing the reference count when paired with |
I just realised, it's the other way around: you removed passing by reference. This is totally fine then! However, I wonder why you didn't apply that to all cases. For example: |
The implementation of the constructor does not actually save a reference to ATNConfig, it only accesses members. Realistically it should probably just accept |
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.
@parrt This patch is ready to merge.
something is weird here with the unit test. Let me rerun them. Still looks messed up. Even Python3 says:
Is it possible this PR is based on a previous version where we had the CI builds messed up? @ericvergnaud any ideas? |
3068a2e
to
8f45e71
Compare
Rebased off of master. Let's see what happens. |
All passed now, was due to being on an older base of master. |
Thanks again for all your help! |
Various changes related to optimizations, cleanup, and const correctness fixes. The optimizations are related to
std::shared_ptr
and getting rid of unnecessary copying when possible as we as some prerequisite work for future improvements. The cleanup is marking things as final or removing odd whitespace. The const correctness is self explanatory.Additionally this makes LL1Analyzer final and removes its virtual methods. Its not possible for generated code to override the LL1Analyzer and having virtual in the hot path is not free, unlike Java. In C++ virtual methods effectively guarantee CPU cache misses.
Lastly it moves a few methods in the hot path to be inline, specifically Recognizer::set/getState.