Skip to content

Commit 9434773

Browse files
Merge branch 'gh-132042-optimize-class-creation' of github.com:sergey-miryanov/cpython into gh-132042-optimize-class-creation
2 parents dbf869f + af8ce30 commit 9434773

2 files changed

Lines changed: 7 additions & 7 deletions

File tree

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Improve class creation times by up to 40%. Patch by Sergey Miryanov.
1+
Improve class creation times by up to 40% by pre-computing type slots just once. Patch by Sergey Miryanov.

Objects/typeobject.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11298,7 +11298,7 @@ _PyType_InitSlotDefs(PyInterpreterState *interp)
1129811298
pytype_slotdef *p;
1129911299
Py_ssize_t idx = 0;
1130011300
for (p = slotdefs; p->name_strobj; p++, idx++) {
11301-
assert (idx < 255);
11301+
assert(idx < 255);
1130211302

1130311303
if (PyDict_GetItemRef(cache, p->name_strobj, &bytearray) < 0) {
1130411304
goto error;
@@ -11319,11 +11319,11 @@ _PyType_InitSlotDefs(PyInterpreterState *interp)
1131911319
}
1132011320
}
1132111321

11322-
assert (PyByteArray_CheckExact(bytearray));
11322+
assert(PyByteArray_CheckExact(bytearray));
1132311323
uint8_t *data = (uint8_t *)PyByteArray_AS_STRING(bytearray);
1132411324

1132511325
data[0] += 1;
11326-
assert (data[0] < MAX_EQUIV);
11326+
assert(data[0] < MAX_EQUIV);
1132711327

1132811328
data[data[0]] = (uint8_t)idx;
1132911329

@@ -11332,9 +11332,9 @@ _PyType_InitSlotDefs(PyInterpreterState *interp)
1133211332

1133311333
memset(slotdefs_name_counts, 0, sizeof(slotdefs_name_counts));
1133411334

11335-
Py_ssize_t pos=0;
11336-
PyObject *key=NULL;
11337-
PyObject *value=NULL;
11335+
Py_ssize_t pos = 0;
11336+
PyObject *key = NULL;
11337+
PyObject *value = NULL;
1133811338
while (PyDict_Next(cache, &pos, &key, &value)) {
1133911339
uint8_t *data = (uint8_t *)PyByteArray_AS_STRING(value);
1134011340
uint8_t n = data[0];

0 commit comments

Comments
 (0)