New submission from Serhiy Storchaka:

In additional to C API functions PyTuple_Size() and PyList_Size() there are 
fast macros PyTuple_GET_SIZE() and PyList_GET_SIZE() for getting the size of a 
tuple or a list. But for dicts there is just PyDict_Size(). It is not just 
slower than a macro, but can return an error (actually this never happens in 
CPython core and extensions).

Proposed patch adds new private macro _PyDict_GET_SIZE() and makes the code 
using it instead of PyDict_Size(). I don't expect significant performance gain 
except perhaps few checks that a dict is empty. The main advantage to me is 
that not checking the result for error no longer looks as potential bug.

----------
components: Interpreter Core
files: _PyDict_GET_SIZE.patch
keywords: patch
messages: 283099
nosy: haypo, inada.naoki, serhiy.storchaka
priority: normal
severity: normal
stage: patch review
status: open
title: Add a macro for dict size
type: enhancement
versions: Python 3.7
Added file: http://bugs.python.org/file45874/_PyDict_GET_SIZE.patch

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

Reply via email to