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.
diff --git a/Objects/dictobject.c b/Objects/dictobject.c
index 23ca442..f0a07d7 100644
--- a/Objects/dictobject.c
+++ b/Objects/dictobject.c
@@ -2198,6 +2198,16 @@
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 *
@@ -2213,6 +2223,16 @@
}
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)
{
PyObject *kv;