This issue tracker has been migrated to GitHub ,
and is currently read-only.
For more information,
see the GitHub FAQs in the Python's Developer Guide.
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 || ((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++] = '=';
|
|||
| 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 -> closed nosy: + orsenthil messages: + msg120853 resolution: fixed stage: commit review -> resolved |
| 2010年11月06日 09:22:19 | nikai | set | messages: + msg120599 |
| 2010年11月06日 02:56:57 | terry.reedy | set | messages: + msg120573 |
| 2010年11月06日 00:30:35 | nikai | set | messages: + msg120565 |
| 2010年11月05日 22:57:07 | terry.reedy | set | versions:
+ Python 3.2, - Python 3.3 nosy: + terry.reedy messages: + msg120551 type: enhancement -> performance stage: commit review |
| 2010年11月05日 12:37:09 | nikai | set | files:
+ python-binascii.diff keywords: + patch |
| 2010年11月05日 12:31:20 | nikai | create | |