Skip to content

Commit 0e7129f

Browse files
committed
Replace _Py_IDENTIFIER
1 parent 9f569d7 commit 0e7129f

File tree

5 files changed

+19
-112
lines changed

5 files changed

+19
-112
lines changed

mypyc/lib-rt/bytes_extra_ops.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,5 @@ PyObject *CPyBytes_Translate(PyObject *bytes, PyObject *table) {
4141
}
4242

4343
// Fallback to Python method call for non-exact types or non-standard tables
44-
_Py_IDENTIFIER(translate);
45-
PyObject *name = _PyUnicode_FromId(&PyId_translate);
46-
if (name == NULL) {
47-
return NULL;
48-
}
49-
return PyObject_CallMethodOneArg(bytes, name, table);
44+
return PyObject_CallMethodOneArg(bytes, mypyc_interned_str.translate, table);
5045
}

mypyc/lib-rt/bytes_ops.c

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,7 @@ PyObject *CPyBytes_Join(PyObject *sep, PyObject *iter) {
101101
if (PyBytes_CheckExact(sep)) {
102102
return PyBytes_Join(sep, iter);
103103
} else {
104-
_Py_IDENTIFIER(join);
105-
PyObject *name = _PyUnicode_FromId(&PyId_join); /* borrowed */
106-
if (name == NULL) {
107-
return NULL;
108-
}
109-
return PyObject_CallMethodOneArg(sep, name, iter);
104+
return PyObject_CallMethodOneArg(sep, mypyc_interned_str.join, iter);
110105
}
111106
}
112107

@@ -193,12 +188,7 @@ int CPyBytes_Startswith(PyObject *self, PyObject *subobj) {
193188

194189
return memcmp(self_buf, subobj_buf, (size_t)subobj_len) == 0 ? 1 : 0;
195190
}
196-
_Py_IDENTIFIER(startswith);
197-
PyObject *name = _PyUnicode_FromId(&PyId_startswith);
198-
if (name == NULL) {
199-
return 2;
200-
}
201-
PyObject *result = PyObject_CallMethodOneArg(self, name, subobj);
191+
PyObject *result = PyObject_CallMethodOneArg(self, mypyc_interned_str.startswith, subobj);
202192
if (result == NULL) {
203193
return 2;
204194
}

mypyc/lib-rt/dict_ops.c

Lines changed: 12 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,7 @@ PyObject *CPyDict_SetDefault(PyObject *dict, PyObject *key, PyObject *value) {
7777
Py_XINCREF(ret);
7878
return ret;
7979
}
80-
_Py_IDENTIFIER(setdefault);
81-
PyObject *name = _PyUnicode_FromId(&PyId_setdefault); /* borrowed */
82-
if (name == NULL) {
83-
return NULL;
84-
}
85-
return PyObject_CallMethodObjArgs(dict, name, key, value, NULL);
80+
return PyObject_CallMethodObjArgs(dict, mypyc_interned_str.setdefault, key, value, NULL);
8681
}
8782

8883
PyObject *CPyDict_SetDefaultWithNone(PyObject *dict, PyObject *key) {
@@ -136,12 +131,7 @@ static inline int CPy_ObjectToStatus(PyObject *obj) {
136131
}
137132

138133
static int CPyDict_UpdateGeneral(PyObject *dict, PyObject *stuff) {
139-
_Py_IDENTIFIER(update);
140-
PyObject *name = _PyUnicode_FromId(&PyId_update); /* borrowed */
141-
if (name == NULL) {
142-
return -1;
143-
}
144-
PyObject *res = PyObject_CallMethodOneArg(dict, name, stuff);
134+
PyObject *res = PyObject_CallMethodOneArg(dict, mypyc_interned_str.update, stuff);
145135
return CPy_ObjectToStatus(res);
146136
}
147137

@@ -207,36 +197,21 @@ PyObject *CPyDict_KeysView(PyObject *dict) {
207197
if (PyDict_CheckExact(dict)){
208198
return _CPyDictView_New(dict, &PyDictKeys_Type);
209199
}
210-
_Py_IDENTIFIER(keys);
211-
PyObject *name = _PyUnicode_FromId(&PyId_keys); /* borrowed */
212-
if (name == NULL) {
213-
return NULL;
214-
}
215-
return PyObject_CallMethodNoArgs(dict, name);
200+
return PyObject_CallMethodNoArgs(dict, mypyc_interned_str.keys);
216201
}
217202

218203
PyObject *CPyDict_ValuesView(PyObject *dict) {
219204
if (PyDict_CheckExact(dict)){
220205
return _CPyDictView_New(dict, &PyDictValues_Type);
221206
}
222-
_Py_IDENTIFIER(values);
223-
PyObject *name = _PyUnicode_FromId(&PyId_values); /* borrowed */
224-
if (name == NULL) {
225-
return NULL;
226-
}
227-
return PyObject_CallMethodNoArgs(dict, name);
207+
return PyObject_CallMethodNoArgs(dict, mypyc_interned_str.values);
228208
}
229209

230210
PyObject *CPyDict_ItemsView(PyObject *dict) {
231211
if (PyDict_CheckExact(dict)){
232212
return _CPyDictView_New(dict, &PyDictItems_Type);
233213
}
234-
_Py_IDENTIFIER(items);
235-
PyObject *name = _PyUnicode_FromId(&PyId_items); /* borrowed */
236-
if (name == NULL) {
237-
return NULL;
238-
}
239-
return PyObject_CallMethodNoArgs(dict, name);
214+
return PyObject_CallMethodNoArgs(dict, mypyc_interned_str.items);
240215
}
241216

242217
PyObject *CPyDict_Keys(PyObject *dict) {
@@ -245,12 +220,7 @@ PyObject *CPyDict_Keys(PyObject *dict) {
245220
}
246221
// Inline generic fallback logic to also return a list.
247222
PyObject *list = PyList_New(0);
248-
_Py_IDENTIFIER(keys);
249-
PyObject *name = _PyUnicode_FromId(&PyId_keys); /* borrowed */
250-
if (name == NULL) {
251-
return NULL;
252-
}
253-
PyObject *view = PyObject_CallMethodNoArgs(dict, name);
223+
PyObject *view = PyObject_CallMethodNoArgs(dict, mypyc_interned_str.keys);
254224
if (view == NULL) {
255225
return NULL;
256226
}
@@ -268,12 +238,7 @@ PyObject *CPyDict_Values(PyObject *dict) {
268238
}
269239
// Inline generic fallback logic to also return a list.
270240
PyObject *list = PyList_New(0);
271-
_Py_IDENTIFIER(values);
272-
PyObject *name = _PyUnicode_FromId(&PyId_values); /* borrowed */
273-
if (name == NULL) {
274-
return NULL;
275-
}
276-
PyObject *view = PyObject_CallMethodNoArgs(dict, name);
241+
PyObject *view = PyObject_CallMethodNoArgs(dict, mypyc_interned_str.values);
277242
if (view == NULL) {
278243
return NULL;
279244
}
@@ -291,12 +256,7 @@ PyObject *CPyDict_Items(PyObject *dict) {
291256
}
292257
// Inline generic fallback logic to also return a list.
293258
PyObject *list = PyList_New(0);
294-
_Py_IDENTIFIER(items);
295-
PyObject *name = _PyUnicode_FromId(&PyId_items); /* borrowed */
296-
if (name == NULL) {
297-
return NULL;
298-
}
299-
PyObject *view = PyObject_CallMethodNoArgs(dict, name);
259+
PyObject *view = PyObject_CallMethodNoArgs(dict, mypyc_interned_str.items);
300260
if (view == NULL) {
301261
return NULL;
302262
}
@@ -312,12 +272,7 @@ char CPyDict_Clear(PyObject *dict) {
312272
if (PyDict_CheckExact(dict)) {
313273
PyDict_Clear(dict);
314274
} else {
315-
_Py_IDENTIFIER(clear);
316-
PyObject *name = _PyUnicode_FromId(&PyId_clear); /* borrowed */
317-
if (name == NULL) {
318-
return 0;
319-
}
320-
PyObject *res = PyObject_CallMethodNoArgs(dict, name);
275+
PyObject *res = PyObject_CallMethodNoArgs(dict, mypyc_interned_str.clear);
321276
if (res == NULL) {
322277
return 0;
323278
}
@@ -329,12 +284,7 @@ PyObject *CPyDict_Copy(PyObject *dict) {
329284
if (PyDict_CheckExact(dict)) {
330285
return PyDict_Copy(dict);
331286
}
332-
_Py_IDENTIFIER(copy);
333-
PyObject *name = _PyUnicode_FromId(&PyId_copy); /* borrowed */
334-
if (name == NULL) {
335-
return NULL;
336-
}
337-
return PyObject_CallMethodNoArgs(dict, name);
287+
return PyObject_CallMethodNoArgs(dict, mypyc_interned_str.copy);
338288
}
339289

340290
PyObject *CPyDict_GetKeysIter(PyObject *dict) {
@@ -352,12 +302,7 @@ PyObject *CPyDict_GetItemsIter(PyObject *dict) {
352302
Py_INCREF(dict);
353303
return dict;
354304
}
355-
_Py_IDENTIFIER(items);
356-
PyObject *name = _PyUnicode_FromId(&PyId_items); /* borrowed */
357-
if (name == NULL) {
358-
return NULL;
359-
}
360-
PyObject *view = PyObject_CallMethodNoArgs(dict, name);
305+
PyObject *view = PyObject_CallMethodNoArgs(dict, mypyc_interned_str.items);
361306
if (view == NULL) {
362307
return NULL;
363308
}
@@ -372,12 +317,7 @@ PyObject *CPyDict_GetValuesIter(PyObject *dict) {
372317
Py_INCREF(dict);
373318
return dict;
374319
}
375-
_Py_IDENTIFIER(values);
376-
PyObject *name = _PyUnicode_FromId(&PyId_values); /* borrowed */
377-
if (name == NULL) {
378-
return NULL;
379-
}
380-
PyObject *view = PyObject_CallMethodNoArgs(dict, name);
320+
PyObject *view = PyObject_CallMethodNoArgs(dict, mypyc_interned_str.values);
381321
if (view == NULL) {
382322
return NULL;
383323
}

mypyc/lib-rt/list_ops.c

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,7 @@ char CPyList_Clear(PyObject *list) {
3333
if (PyList_CheckExact(list)) {
3434
PyList_Clear(list);
3535
} else {
36-
_Py_IDENTIFIER(clear);
37-
PyObject *name = _PyUnicode_FromId(&PyId_clear);
38-
if (name == NULL) {
39-
return 0;
40-
}
41-
PyObject *res = PyObject_CallMethodNoArgs(list, name);
36+
PyObject *res = PyObject_CallMethodNoArgs(list, mypyc_interned_str.clear);
4237
if (res == NULL) {
4338
return 0;
4439
}
@@ -50,13 +45,7 @@ PyObject *CPyList_Copy(PyObject *list) {
5045
if(PyList_CheckExact(list)) {
5146
return PyList_GetSlice(list, 0, PyList_GET_SIZE(list));
5247
}
53-
_Py_IDENTIFIER(copy);
54-
55-
PyObject *name = _PyUnicode_FromId(&PyId_copy);
56-
if (name == NULL) {
57-
return NULL;
58-
}
59-
return PyObject_CallMethodNoArgs(list, name);
48+
return PyObject_CallMethodNoArgs(list, mypyc_interned_str.copy);
6049
}
6150

6251
PyObject *CPyList_GetItemShort(PyObject *list, CPyTagged index) {

mypyc/lib-rt/misc_ops.c

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,7 @@ PyObject *CPyIter_Send(PyObject *iter, PyObject *val)
2929
if (Py_IsNone(val)) {
3030
return CPyIter_Next(iter);
3131
} else {
32-
_Py_IDENTIFIER(send);
33-
PyObject *name = _PyUnicode_FromId(&PyId_send); /* borrowed */
34-
if (name == NULL) {
35-
return NULL;
36-
}
37-
return PyObject_CallMethodOneArg(iter, name, val);
32+
return PyObject_CallMethodOneArg(iter, mypyc_interned_str.send, val);
3833
}
3934
}
4035

@@ -1065,9 +1060,7 @@ PyObject *CPy_GetName(PyObject *obj) {
10651060
if (PyType_Check(obj)) {
10661061
return PyType_GetName((PyTypeObject *)obj);
10671062
}
1068-
_Py_IDENTIFIER(__name__);
1069-
PyObject *name = _PyUnicode_FromId(&PyId___name__); /* borrowed */
1070-
return PyObject_GetAttr(obj, name);
1063+
return PyObject_GetAttr(obj, mypyc_interned_str.__name__);
10711064
}
10721065

10731066
#endif

0 commit comments

Comments
 (0)