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

Rule to spot (possibly) inefficient conditional expressions #599

Closed
chavacava opened this issue Oct 16, 2021 · 1 comment · Fixed by #603
Closed

Rule to spot (possibly) inefficient conditional expressions #599

chavacava opened this issue Oct 16, 2021 · 1 comment · Fixed by #603
Assignees
Labels
hacktoberfest rule proposal Issue proposing a new rule

Comments

@chavacava
Copy link
Collaborator

In some cases it is possible to alter the order of terms in a conditional expression to speed up its average evaluation time.
For example:

if isGenerated(content) && !config.IgnoreGeneratedHeader {

can be safely (i.e. no change in the semantic) rewritten as

if !config.IgnoreGeneratedHeader && isGenerated(content) {

To avoid making a function call in those cases where !config.IgnoreGeneratedHeader evaluates to false

A rule like this can not have a confidence of 1 because the analysis does not have enough context information to know whether altering the order of terms is semantically safe (for example, when the function is not pure).

@chavacava chavacava added rule proposal Issue proposing a new rule hacktoberfest labels Oct 16, 2021
@doniacld
Copy link
Contributor

Hola @chavacava
I would be happy to add this new rule, if you could assign me the issue ?
Thanks

doniacld added a commit to doniacld/revive that referenced this issue Oct 18, 2021
doniacld added a commit to doniacld/revive that referenced this issue Oct 18, 2021
doniacld added a commit to doniacld/revive that referenced this issue Oct 21, 2021
doniacld added a commit to doniacld/revive that referenced this issue Oct 22, 2021
chavacava added a commit that referenced this issue Oct 23, 2021

Co-authored-by: SalvadorC <salvadorcavadini+github@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hacktoberfest rule proposal Issue proposing a new rule
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants