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

Code quality: Repeated branch in conditional chain #388

Open
krishnakumarg1984 opened this issue Jun 23, 2023 · 2 comments
Open

Code quality: Repeated branch in conditional chain #388

krishnakumarg1984 opened this issue Jun 23, 2023 · 2 comments

Comments

@krishnakumarg1984
Copy link
Collaborator

krishnakumarg1984 commented Jun 23, 2023

In sopt/cpp/chained_operators.h, we have

    if (funcs.size() == 1)
      (*first)(output, input);
    else if (funcs.size() % 2 == 1)
      (*first)(output, input);
    else {
      (*first)(*buffer, input);
      first++;
      (*first)(output, *buffer);
    }

As we can see, the if statement and the elseif has the same statement in their bodies. This can be cleaned up to get rid of the redundancy.

@SJaffa
Copy link
Contributor

SJaffa commented Jul 4, 2023

Doesn't 1%2 ==1 so the first two conditions are both true if funcs.size ==1? So you could just remove the first condition entirely.

@krishnakumarg1984
Copy link
Collaborator Author

@SJaffa Agreed. Shall I do that then?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants