Stefan Behnel <stefan...@behnel.de> added the comment:

The overhead of calling PyErr_Occurred() is definitely negligible in something 
as involved as PyDict_GetItemStringWithError(), where a mere key lookup first 
has to fire up the string decoder on a C character buffer to create a new 
string object and then calculate its hash value, just to throw away all that 
right after the tiny time interval that it takes to look up the key in the 
dict. It is not something I would encourage anyone to do in code that has only 
the slightest excuse for being implemented in C. :)

Rather, I would propose to open up the ID-String API that CPython uses 
internally, so that user code can benefit from fast lookups of interned strings 
with pre-initialised hash values, without having to care about creating and 
cleaning up string constants themselves all the time.

(FWIW, Cython also generates interned string constants automatically, but does 
not currently use the ID-API, also because it does it for *all* its strings, 
not just those that resemble identifiers etc.)

----------
nosy: +scoder

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

Reply via email to