Issue 10324: Modules/binascii.c: simplify expressions (original) (raw)

Created on 2010-11-05 12:31 by nikai, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
python-binascii.diff nikai,2010-11-05 12:37 patch
Messages (6)
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) * (Python committer) 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) * (Python committer) 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) * (Python committer) 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.
History
Date User Action Args
2022-04-11 14:57:08 admin set github: 54533
2010-11-09 10:02:57 orsenthil set status: open -> closednosy: + orsenthilmessages: + resolution: fixedstage: commit review -> resolved
2010-11-06 09:22:19 nikai set messages: +
2010-11-06 02:56:57 terry.reedy set messages: +
2010-11-06 00:30:35 nikai set messages: +
2010-11-05 22:57:07 terry.reedy set versions: + Python 3.2, - Python 3.3nosy: + terry.reedymessages: + type: enhancement -> performancestage: commit review
2010-11-05 12:37:09 nikai set files: + python-binascii.diffkeywords: + patch
2010-11-05 12:31:20 nikai create