msg120490 - (view) |
Author: Nicolas Kaiser (nikai) |
Date: 2010-11-05 12:31 |
|
|
|
|
|
|
|
Hi there! I noticed two expressions that can be simplified like: (a | |
(!a && b)) => (a |
|
b) Best regards, Nicolas Kaiser --- --- 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 |
msg120551 - (view) |
Author: Terry J. Reedy (terry.reedy) *  |
Date: 2010-11-05 22:57 |
|
|
|
|
|
|
|
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? |
|
|
|
|
|
|
|
|
msg120565 - (view) |
Author: Nicolas Kaiser (nikai) |
Date: 2010-11-06 00:30 |
|
|
|
|
|
|
|
That's ./Lib/test/test_unittest.py? With patched builds of Python 2.6.5 and 3.1.2: ---------------------------------------------------------------------- Ran 126 tests in 0.015s OK ---------------------------------------------------------------------- Ran 187 tests in 0.054s OK |
|
|
|
|
|
|
|
|
|
msg120573 - (view) |
Author: Terry J. Reedy (terry.reedy) *  |
Date: 2010-11-06 02:56 |
|
|
|
|
|
|
|
test_binascii.py |
|
|
|
|
|
|
|
|
|
msg120599 - (view) |
Author: Nicolas Kaiser (nikai) |
Date: 2010-11-06 09:22 |
|
|
|
|
|
|
|
Sorry, found it - with patched builds of Python 2.6.5 and 3.1.2: python2.6 test_binascii.py test_base64invalid (__main__.BinASCIITest) ... ok test_base64valid (__main__.BinASCIITest) ... ok test_crc32 (__main__.BinASCIITest) ... ok test_empty_string (__main__.BinASCIITest) ... ok test_exceptions (__main__.BinASCIITest) ... ok test_functions (__main__.BinASCIITest) ... ok test_hex (__main__.BinASCIITest) ... ok test_qp (__main__.BinASCIITest) ... ok test_uu (__main__.BinASCIITest) ... ok ---------------------------------------------------------------------- Ran 9 tests in 0.002s OK python3.1 test_binascii.py test_base64invalid (__main__.BinASCIITest) ... ok test_base64valid (__main__.BinASCIITest) ... ok test_crc32 (__main__.BinASCIITest) ... ok test_empty_string (__main__.BinASCIITest) ... ok test_exceptions (__main__.BinASCIITest) ... ok test_functions (__main__.BinASCIITest) ... ok test_hex (__main__.BinASCIITest) ... ok test_no_binary_strings (__main__.BinASCIITest) ... ok test_qp (__main__.BinASCIITest) ... ok test_uu (__main__.BinASCIITest) ... ok ---------------------------------------------------------------------- Ran 10 tests in 0.006s OK |
|
|
|
|
|
|
|
|
|
msg120853 - (view) |
Author: Senthil Kumaran (orsenthil) *  |
Date: 2010-11-09 10:02 |
|
|
|
|
|
|
|
At first, I was worried if this simplification would cause any harm to readability of the algorithm. Fortunately, it didn't. Committed in r86357. |
|
|
|
|
|
|
|
|
|