mirror of
https://github.com/python/cpython.git
synced 2025-12-15 21:44:50 +00:00
Issue #14383: Add _PyDict_GetItemId() and _PyDict_SetItemId() functions
These functions simplify the usage of static constant Unicode strings. Generalize the usage of _Py_Identifier in ceval.c and typeobject.c.
This commit is contained in:
parent
70b2e1e7d9
commit
3c1e48176e
4 changed files with 118 additions and 122 deletions
|
|
@ -2198,6 +2198,16 @@ PyTypeObject PyDict_Type = {
|
|||
PyObject_GC_Del, /* tp_free */
|
||||
};
|
||||
|
||||
PyObject *
|
||||
_PyDict_GetItemId(PyObject *dp, struct _Py_Identifier *key)
|
||||
{
|
||||
PyObject *kv;
|
||||
kv = _PyUnicode_FromId(key); /* borrowed */
|
||||
if (kv == NULL)
|
||||
return NULL;
|
||||
return PyDict_GetItem(dp, kv);
|
||||
}
|
||||
|
||||
/* For backward compatibility with old dictionary interface */
|
||||
|
||||
PyObject *
|
||||
|
|
@ -2212,6 +2222,16 @@ PyDict_GetItemString(PyObject *v, const char *key)
|
|||
return rv;
|
||||
}
|
||||
|
||||
int
|
||||
_PyDict_SetItemId(PyObject *v, struct _Py_Identifier *key, PyObject *item)
|
||||
{
|
||||
PyObject *kv;
|
||||
kv = _PyUnicode_FromId(key); /* borrowed */
|
||||
if (kv == NULL)
|
||||
return -1;
|
||||
return PyDict_SetItem(v, kv, item);
|
||||
}
|
||||
|
||||
int
|
||||
PyDict_SetItemString(PyObject *v, const char *key, PyObject *item)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue