New submission from Serhiy Storchaka:

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(!)

----------
components: Extension Modules
files: odict_cleanup.patch
keywords: patch
messages: 253033
nosy: eric.snow, rhettinger, serhiy.storchaka
priority: normal
severity: normal
stage: patch review
status: open
title: Clean up and fix OrderedDict
type: behavior
versions: Python 3.5, Python 3.6
Added file: http://bugs.python.org/file40785/odict_cleanup.patch

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue25410>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to