On Thu, Feb 3, 2022 at 11:49 PM Eric Snow <ericsnowcurren...@gmail.com> wrote:
> I suppose I'd like to know what the value of _Py_IDENTIFIER() is for
> 3rd party modules.

_Py_IDENTIFIER() API is simple and short, Python creates the Python
string object automatically, *and* clears this object at exit. It's
convenient.

On the other side, functions like PyDict_GetItemString() call
PyUnicode_FromString(): it allocates memory on the heap, it decodes
the bytes string from UTF-8, and then deallocates the memory. It's
inefficient just for a dict lookup.

In the _Py_IDENTIFIER() API, _PyUnicode_FromId() calls
PyUnicode_InternInPlace() which makes dict lookup even more efficient.

Victor
-- 
Night gathers, and now my watch begins. It shall not end until my death.
_______________________________________________
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/ZYONQJPBC7IEIJVUTUBHNZXVOV7YOBUF/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to