-
Notifications
You must be signed in to change notification settings - Fork 13
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
Refactor parser #346
Refactor parser #346
Conversation
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## devel #346 +/- ##
=======================================
Coverage 72.94% 72.95%
=======================================
Files 33 33
Lines 4144 4148 +4
Branches 955 955
=======================================
+ Hits 3023 3026 +3
- Misses 740 741 +1
Partials 381 381
☔ View full report in Codecov by Sentry. |
for (int j = static_cast<int>(opstack.size())-1; j >= 0; --j) { | ||
size_t j_size_t{ static_cast<size_t>(j) }; | ||
assert(!opstack[j_size_t].is_operand()); | ||
if (opstack[j_size_t].is_leftpar()) | ||
auto formula_node_opstack_it{ opstack.begin() + j }; |
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.
Isn't this just iterating from end to begin? So we could have
for (auto formula_node_opstack_it = opstack.rbegin(); formula_node_opstack_it != opstack.rend(); ++formula_node_opstack_it)
?
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 are right. It should be possible to refactor this as you say. I will investigate.
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.
The int arithmetic is there so you can do erase()
in the vector. It will not work with a reverse iterator. I would keep it as it is, or rework the logic to not have to erase inside 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.
I think it could be done somehow with erase()
, because it returns iterator, but a forward one.
But moving erasing outside the loop would probably be the best.
FormulaNode node{}; | ||
std::vector<FormulaGraph> children{}; | ||
|
||
FormulaGraph() = default; | ||
FormulaGraph(const FormulaNode& n) : node(n), children() {} | ||
FormulaGraph(FormulaNode&& n) : node(std::move(n)), children() {} | ||
explicit FormulaGraph(const FormulaNode& n) : node(n), children() { children.reserve(2); } |
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.
just wandering, can you put the two alredy to the the line 129 with the declaration?
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.
No, vector has no such constructor, unfortunately. It can be done with a lambda or a named function inside the parentheses in the initialization list. Something like
FormulaGraph() : children([](){ std::vector<FormulaNode> children; children.reserve(100); return children;}()) {}
if (token.second) { // is quoted? | ||
result.push_back(std::move(token)); | ||
continue; | ||
} | ||
|
||
const std::string_view token_string = token.first; | ||
size_t last_operator = 0; | ||
const std::string_view token_string{ token.first }; |
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.
why this everywhere actually?
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 mena why to initialize things with the curly brackets {bla} instead of = bla?
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 it is some C++ idiom, that is advised to use. I myself don't like it.
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.
It is to prevent narrowing of the types (https://stackoverflow.com/a/27755143), but naturally, C++ community has to make sure it is ugly as pug's arse.
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.
Exactly as you say. It is a good idea, only horribly implemented as far as visualization goes. But it helps indeed and warns you about potential implicit conversion bugs. In modern C++, it should always be preferred over assignment operator.
anyway, great! |
if (token.second) { // is quoted? | ||
result.push_back(std::move(token)); | ||
continue; | ||
} | ||
|
||
const std::string_view token_string = token.first; | ||
size_t last_operator = 0; | ||
const std::string_view token_string{ token.first }; |
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 mena why to initialize things with the curly brackets {bla} instead of = bla?
Weird thing, if you look at the checks - the performance tests, then you can see that complement got faster. |
if (token.second) { // is quoted? | ||
result.push_back(std::move(token)); | ||
continue; | ||
} | ||
|
||
const std::string_view token_string = token.first; | ||
size_t last_operator = 0; | ||
const std::string_view token_string{ token.first }; |
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 it is some C++ idiom, that is advised to use. I myself don't like it.
if (token.second) { // is quoted? | ||
result.push_back(std::move(token)); | ||
continue; | ||
} | ||
|
||
const std::string_view token_string = token.first; | ||
size_t last_operator = 0; | ||
const std::string_view token_string{ token.first }; |
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.
It is to prevent narrowing of the types (https://stackoverflow.com/a/27755143), but naturally, C++ community has to make sure it is ugly as pug's arse.
The checks are passing, we decided to move with this PR. Please @Adda0 check the rest of the conversations post mortem. Oaw oaw, thanks. |
Complement got slower, not faster. I think this is only a deviation which stems from us running the performance tests only once. The runtimes are not precise, and it runs faster one time and slower another time. Nothing except for parsing and mintermization can change in this PR. |
The changes from the discussions were addressed and will be part of a future parser optimization PR. |
This PR improves the performance of parser. More optimizations are to come, as well as a possible rewrite of the formula parser.