-
Notifications
You must be signed in to change notification settings - Fork 279
Refactor: simplify an if statement #4281
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: simplify an if statement #4281
Conversation
Note if you don't like option 2, note the first commit is less ambitious in this trivial tidy up. |
return false; | ||
const bool is_dynamic = expr.type().get_bool(ID_C_dynamic); | ||
const auto symbol_expr = expr_try_dynamic_cast<symbol_exprt>(expr); | ||
return is_dynamic && symbol_expr && |
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.
should be ||
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 testing you 😉
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 first commit definitively is an improvement, the second commit needs to be bug fixed (and I'm happy that CI rejected it), or should maybe dropped altogether. Your call :-)
|
||
return expr.id() == ID_symbol && | ||
const bool is_dynamic = expr.type().get_bool(ID_C_dynamic); | ||
const auto symbol_expr = expr_try_dynamic_cast<symbol_exprt>(expr); |
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.
Apart from the bug that @romainbrenguier spotted, this approach has the downside that we do extra work that may never be necessary in case is_dynamic
is true. Could we just do
return expr.type().get_bool(ID_C_dynamic) || (... return statement from the first commit ...);
?
I don't think this is super performance critical, but I don't think this is a massive improvement either.
Without branching it is simpler to see what the condition is
5370e2d
to
86b5e11
Compare
Done as requested. |
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.
✔️
Passed Diffblue compatibility checks (cbmc commit: 86b5e11).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/102469149
Spotted this doing #3481 - if anyone doesn't like this, I'll simply drop it.