Skip to content

Commit e75fc14

Browse files
committed
Issue #19514: Deduplicate some _Py_IDENTIFIER declarations.
Patch by Andrei Dorian Duma.
1 parent d029359 commit e75fc14

File tree

5 files changed

+18
-28
lines changed

5 files changed

+18
-28
lines changed

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ Projected release date: 2013-11-24
1010
Core and Builtins
1111
-----------------
1212

13+
- Issue #19514: Deduplicate some _Py_IDENTIFIER declarations.
14+
Patch by Andrei Dorian Duma.
15+
1316
- Issue #17936: Fix O(n**2) behaviour when adding or removing many subclasses
1417
of a given type.
1518

Modules/_bisectmodule.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ Converted to C by Dmitry Vasiliev (dima at hlabs.spb.ru).
66
#define PY_SSIZE_T_CLEAN
77
#include "Python.h"
88

9+
_Py_IDENTIFIER(insert);
10+
911
static Py_ssize_t
1012
internal_bisect_right(PyObject *list, PyObject *item, Py_ssize_t lo, Py_ssize_t hi)
1113
{
@@ -90,8 +92,6 @@ insort_right(PyObject *self, PyObject *args, PyObject *kw)
9092
if (PyList_Insert(list, index, item) < 0)
9193
return NULL;
9294
} else {
93-
_Py_IDENTIFIER(insert);
94-
9595
result = _PyObject_CallMethodId(list, &PyId_insert, "nO", index, item);
9696
if (result == NULL)
9797
return NULL;
@@ -195,7 +195,6 @@ insort_left(PyObject *self, PyObject *args, PyObject *kw)
195195
if (PyList_Insert(list, index, item) < 0)
196196
return NULL;
197197
} else {
198-
_Py_IDENTIFIER(insert);
199198
result = _PyObject_CallMethodId(list, &PyId_insert, "nO", index, item);
200199
if (result == NULL)
201200
return NULL;

Modules/_datetimemodule.c

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,11 @@ static PyTypeObject PyDateTime_TimeType;
104104
static PyTypeObject PyDateTime_TZInfoType;
105105
static PyTypeObject PyDateTime_TimeZoneType;
106106

107+
_Py_IDENTIFIER(as_integer_ratio);
108+
_Py_IDENTIFIER(fromutc);
109+
_Py_IDENTIFIER(isoformat);
110+
_Py_IDENTIFIER(strftime);
111+
107112
/* ---------------------------------------------------------------------------
108113
* Math utilities.
109114
*/
@@ -1277,8 +1282,6 @@ wrap_strftime(PyObject *object, PyObject *format, PyObject *timetuple,
12771282
goto Done;
12781283
format = PyUnicode_FromString(PyBytes_AS_STRING(newfmt));
12791284
if (format != NULL) {
1280-
_Py_IDENTIFIER(strftime);
1281-
12821285
result = _PyObject_CallMethodId(time, &PyId_strftime, "OO",
12831286
format, timetuple, NULL);
12841287
Py_DECREF(format);
@@ -1566,7 +1569,6 @@ multiply_float_timedelta(PyObject *floatobj, PyDateTime_Delta *delta)
15661569
PyObject *result = NULL;
15671570
PyObject *pyus_in = NULL, *temp, *pyus_out;
15681571
PyObject *ratio = NULL;
1569-
_Py_IDENTIFIER(as_integer_ratio);
15701572

15711573
pyus_in = delta_to_microseconds(delta);
15721574
if (pyus_in == NULL)
@@ -1665,7 +1667,6 @@ truedivide_timedelta_float(PyDateTime_Delta *delta, PyObject *f)
16651667
PyObject *result = NULL;
16661668
PyObject *pyus_in = NULL, *temp, *pyus_out;
16671669
PyObject *ratio = NULL;
1668-
_Py_IDENTIFIER(as_integer_ratio);
16691670

16701671
pyus_in = delta_to_microseconds(delta);
16711672
if (pyus_in == NULL)
@@ -2635,8 +2636,6 @@ date_isoformat(PyDateTime_Date *self)
26352636
static PyObject *
26362637
date_str(PyDateTime_Date *self)
26372638
{
2638-
_Py_IDENTIFIER(isoformat);
2639-
26402639
return _PyObject_CallMethodId((PyObject *)self, &PyId_isoformat, "()");
26412640
}
26422641

@@ -2676,7 +2675,6 @@ static PyObject *
26762675
date_format(PyDateTime_Date *self, PyObject *args)
26772676
{
26782677
PyObject *format;
2679-
_Py_IDENTIFIER(strftime);
26802678

26812679
if (!PyArg_ParseTuple(args, "U:__format__", &format))
26822680
return NULL;
@@ -3593,8 +3591,6 @@ time_repr(PyDateTime_Time *self)
35933591
static PyObject *
35943592
time_str(PyDateTime_Time *self)
35953593
{
3596-
_Py_IDENTIFIER(isoformat);
3597-
35983594
return _PyObject_CallMethodId((PyObject *)self, &PyId_isoformat, "()");
35993595
}
36003596

@@ -4207,7 +4203,6 @@ datetime_now_impl(PyObject *cls, PyObject *tz)
42074203
if (self != NULL && tz != Py_None) {
42084204
/* Convert UTC to tzinfo's zone. */
42094205
PyObject *temp = self;
4210-
_Py_IDENTIFIER(fromutc);
42114206

42124207
self = _PyObject_CallMethodId(tz, &PyId_fromutc, "O", self);
42134208
Py_DECREF(temp);
@@ -4246,7 +4241,6 @@ datetime_fromtimestamp(PyObject *cls, PyObject *args, PyObject *kw)
42464241
if (self != NULL && tzinfo != Py_None) {
42474242
/* Convert UTC to tzinfo's zone. */
42484243
PyObject *temp = self;
4249-
_Py_IDENTIFIER(fromutc);
42504244

42514245
self = _PyObject_CallMethodId(tzinfo, &PyId_fromutc, "O", self);
42524246
Py_DECREF(temp);
@@ -4529,8 +4523,6 @@ datetime_repr(PyDateTime_DateTime *self)
45294523
static PyObject *
45304524
datetime_str(PyDateTime_DateTime *self)
45314525
{
4532-
_Py_IDENTIFIER(isoformat);
4533-
45344526
return _PyObject_CallMethodId((PyObject *)self, &PyId_isoformat, "(s)", " ");
45354527
}
45364528

@@ -4809,7 +4801,6 @@ datetime_astimezone(PyDateTime_DateTime *self, PyObject *args, PyObject *kw)
48094801
PyObject *offset;
48104802
PyObject *temp;
48114803
PyObject *tzinfo = Py_None;
4812-
_Py_IDENTIFIER(fromutc);
48134804
static char *keywords[] = {"tz", NULL};
48144805

48154806
if (! PyArg_ParseTupleAndKeywords(args, kw, "|O:astimezone", keywords,

Modules/_sqlite/connection.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@
4141
#endif
4242
#endif
4343

44+
_Py_IDENTIFIER(cursor);
45+
4446
static int pysqlite_connection_set_isolation_level(pysqlite_Connection* self, PyObject* isolation_level);
4547
static void _pysqlite_drop_unused_cursor_references(pysqlite_Connection* self);
4648

@@ -1279,7 +1281,6 @@ PyObject* pysqlite_connection_execute(pysqlite_Connection* self, PyObject* args,
12791281
PyObject* cursor = 0;
12801282
PyObject* result = 0;
12811283
PyObject* method = 0;
1282-
_Py_IDENTIFIER(cursor);
12831284

12841285
cursor = _PyObject_CallMethodId((PyObject*)self, &PyId_cursor, "");
12851286
if (!cursor) {
@@ -1309,7 +1310,6 @@ PyObject* pysqlite_connection_executemany(pysqlite_Connection* self, PyObject* a
13091310
PyObject* cursor = 0;
13101311
PyObject* result = 0;
13111312
PyObject* method = 0;
1312-
_Py_IDENTIFIER(cursor);
13131313

13141314
cursor = _PyObject_CallMethodId((PyObject*)self, &PyId_cursor, "");
13151315
if (!cursor) {
@@ -1339,7 +1339,6 @@ PyObject* pysqlite_connection_executescript(pysqlite_Connection* self, PyObject*
13391339
PyObject* cursor = 0;
13401340
PyObject* result = 0;
13411341
PyObject* method = 0;
1342-
_Py_IDENTIFIER(cursor);
13431342

13441343
cursor = _PyObject_CallMethodId((PyObject*)self, &PyId_cursor, "");
13451344
if (!cursor) {

Objects/typeobject.c

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,20 @@ struct method_cache_entry {
3939
static struct method_cache_entry method_cache[1 << MCACHE_SIZE_EXP];
4040
static unsigned int next_version_tag = 0;
4141

42+
/* alphabetical order */
43+
_Py_IDENTIFIER(__abstractmethods__);
4244
_Py_IDENTIFIER(__class__);
45+
_Py_IDENTIFIER(__delitem__);
4346
_Py_IDENTIFIER(__dict__);
4447
_Py_IDENTIFIER(__doc__);
45-
_Py_IDENTIFIER(__getitem__);
4648
_Py_IDENTIFIER(__getattribute__);
49+
_Py_IDENTIFIER(__getitem__);
4750
_Py_IDENTIFIER(__hash__);
51+
_Py_IDENTIFIER(__len__);
4852
_Py_IDENTIFIER(__module__);
4953
_Py_IDENTIFIER(__name__);
5054
_Py_IDENTIFIER(__new__);
51-
_Py_IDENTIFIER(__abstractmethods__);
55+
_Py_IDENTIFIER(__setitem__);
5256

5357
static PyObject *
5458
slot_tp_new(PyTypeObject *type, PyObject *args, PyObject *kwds);
@@ -5068,7 +5072,6 @@ FUNCNAME(PyObject *self, ARG1TYPE arg1, ARG2TYPE arg2) \
50685072
static Py_ssize_t
50695073
slot_sq_length(PyObject *self)
50705074
{
5071-
_Py_IDENTIFIER(__len__);
50725075
PyObject *res = call_method(self, &PyId___len__, "()");
50735076
Py_ssize_t len;
50745077

@@ -5129,8 +5132,6 @@ static int
51295132
slot_sq_ass_item(PyObject *self, Py_ssize_t index, PyObject *value)
51305133
{
51315134
PyObject *res;
5132-
_Py_IDENTIFIER(__delitem__);
5133-
_Py_IDENTIFIER(__setitem__);
51345135

51355136
if (value == NULL)
51365137
res = call_method(self, &PyId___delitem__, "(n)", index);
@@ -5180,8 +5181,6 @@ static int
51805181
slot_mp_ass_subscript(PyObject *self, PyObject *key, PyObject *value)
51815182
{
51825183
PyObject *res;
5183-
_Py_IDENTIFIER(__delitem__);
5184-
_Py_IDENTIFIER(__setitem__);
51855184

51865185
if (value == NULL)
51875186
res = call_method(self, &PyId___delitem__, "(O)", key);
@@ -5232,7 +5231,6 @@ slot_nb_bool(PyObject *self)
52325231
PyObject *func, *args;
52335232
int result = -1;
52345233
int using_len = 0;
5235-
_Py_IDENTIFIER(__len__);
52365234
_Py_IDENTIFIER(__bool__);
52375235

52385236
func = lookup_maybe(self, &PyId___bool__);

0 commit comments

Comments
 (0)