Message253033
Proposed patch cleans up and fixes minor bugs in C implementation of OrderedDict.
1. Used the "p" format unit instead of manual calling PyObject_True() for parsing boolean parameters.
2. Used _Py_Identifier private API instead of char* API if appropriate.
3. Used Py_TYPE instead of the __class__ attribute as in other extension types.
4. Fixed od_fast_nodes size calculation in __sizeof__().
5. Simplified __reduce__() taking into account that __dict__ is empty in C implementation of OrderedDict.
6. popitem() with wrong number of arguments now raises TypeError instead of KeyError for empty dictionary.
7. Python implementation of move_to_end() calls key comparing only once in common case. C implementation called key comparing twice, it first compares a key with first or last key. Now C implementation calls key comparing only once in common case.
8. Used PyUnicode_FromFormat() instead of str.__mod__ in __repr__().
9. update() now takes into account that args and kwargs are always tuple and dict (if not NULL).
10. Got rid of PyMapping_Items() in update(). PyMapping_Items() creates a copy of items as a list, this is not needed.
Also applied other cleanups. The size of sources is decreased by 105 lines.
Objects/odictobject.c | 194 +-----------------------------!!!!!!!!!!!!!!!!!!
1 file changed, 6 insertions(+), 111 deletions(-), 77 modifications(!) |
|
Date |
User |
Action |
Args |
2015-10-15 08:05:09 | serhiy.storchaka | set | recipients:
+ serhiy.storchaka, rhettinger, eric.snow |
2015-10-15 08:05:08 | serhiy.storchaka | set | messageid: <1444896308.75.0.718152743923.issue25410@psf.upfronthosting.co.za> |
2015-10-15 08:05:08 | serhiy.storchaka | link | issue25410 messages |
2015-10-15 08:05:07 | serhiy.storchaka | create | |
|