Skip to content

Conversation

iluuu1994
Copy link
Member

No description provided.

@TimWolla
Copy link
Member

Was this a manual change or did you use Coccinelle for this? It looks like surprisingly few changes.

@iluuu1994
Copy link
Member Author

iluuu1994 commented Oct 23, 2024

@TimWolla I just used a regex ( & ([a-zA-Z]\w*)\) == \1). I've never tried Coccinelle :) There are a few more I found, but I only changed the code paths I help maintain (i.e. Zend/, ext/standard/, ext/opcache/, etc.).

Also, some of these hits are legitimate, namely when the constant contains multiple bits.

@TimWolla
Copy link
Member

I'll try with Coccinelle when I don't forget, but I assume that the following patch would work:

@@
expression e;
expression b;
@@

- (e & b) == b
+ e & b

Possibly with some extra constraints to exclude locations where it's important that the result is a boolean.

What's the motivation of this patch? Readability? I would expect the compiler to optimize both variants into the same assembly.

@iluuu1994
Copy link
Member Author

Readability, and the fact that it looks like (bitset & flags) == flags) but isn't meaningful as there is only one bit to begin with, which may be confusing.

@iluuu1994 iluuu1994 closed this in e122152 Oct 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants