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
Modules/binascii.c: simplify expressions #54533
Comments
Hi there! I noticed two expressions that can be simplified like: Best regards, --- a/Modules/binascii.c 2010-11-05 13:21:22.075303326 +0100
+++ b/Modules/binascii.c 2010-11-05 13:24:16.986174756 +0100
@@ -1337,8 +1337,7 @@ binascii_b2a_qp (PyObject *self, PyObjec
((data[in] == '\t' || data[in] == ' ') && (in + 1 == datalen)) ||
((data[in] < 33) &&
(data[in] != '\r') && (data[in] != '\n') &&
- (quotetabs ||
- (!quotetabs && ((data[in] != '\t') && (data[in] != ' '))))))
+ (quotetabs || ((data[in] != '\t') && (data[in] != ' ')))))
{
if ((linelen + 3) >= MAXLINESIZE) {
linelen = 0;
@@ -1410,8 +1409,7 @@ binascii_b2a_qp (PyObject *self, PyObjec
((data[in] == '\t' || data[in] == ' ') && (in + 1 == datalen)) ||
((data[in] < 33) &&
(data[in] != '\r') && (data[in] != '\n') &&
- (quotetabs ||
- (!quotetabs && ((data[in] != '\t') && (data[in] != ' '))))))
+ (quotetabs || ((data[in] != '\t') && (data[in] != ' ')))))
{
if ((linelen + 3 )>= MAXLINESIZE) {
odata[out++] = '='; |
As near as I can tell, since && and || are logical rather than bitwise, and since the variable reference 'quotetabs' has no side effect, you are correct. Have you run the unittest on a patched build? |
That's ./Lib/test/test_unittest.py? With patched builds of Python 2.6.5 and 3.1.2: ---------------------------------------------------------------------- OK ---------------------------------------------------------------------- OK |
test_binascii.py |
Sorry, found it - with patched builds of Python 2.6.5 and 3.1.2: python2.6 test_binascii.py ---------------------------------------------------------------------- OK python3.1 test_binascii.py ---------------------------------------------------------------------- OK |
At first, I was worried if this simplification would cause any harm to readability of the algorithm. Fortunately, it didn't. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: