Skip to content

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

Merged
merged 1 commit into from
Feb 27, 2019

Conversation

thk123
Copy link
Contributor

@thk123 thk123 commented Feb 26, 2019

Spotted this doing #3481 - if anyone doesn't like this, I'll simply drop it.

  • Each commit message has a non-empty body, explaining why the change was made.
  • [n/a] Methods or procedures I have added are documented, following the guidelines provided in CODING_STANDARD.md.
  • [n/a] The feature or user visible behaviour I have added or modified has been documented in the User Guide in doc/cprover-manual/
  • [n/a] Regression or unit tests are included, or existing tests cover the modified code (in this case I have detailed which ones those are in the commit message).
  • [n/a] My commit message includes data points confirming performance improvements (if claimed).
  • My PR is restricted to a single feature or bugfix.
  • White-space or formatting changes outside the feature-related changed lines are in commits of their own.

@thk123
Copy link
Contributor Author

thk123 commented Feb 26, 2019

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 &&
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be ||

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just testing you 😉

Copy link
Collaborator

@tautschnig tautschnig left a 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);
Copy link
Collaborator

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
@thk123 thk123 force-pushed the refactor/tidy-over-complicated-if branch from 5370e2d to 86b5e11 Compare February 27, 2019 09:48
@thk123
Copy link
Contributor Author

thk123 commented Feb 27, 2019

Done as requested.

Copy link
Contributor

@allredj allredj left a 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

@thk123 thk123 merged commit a622d44 into diffblue:develop Feb 27, 2019
@thk123 thk123 deleted the refactor/tidy-over-complicated-if branch February 27, 2019 10:35
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.

4 participants