Skip to content

Commit af8ce30

Browse files
Apply suggestions from code review
Co-authored-by: sobolevn <[email protected]>
1 parent 04539cc commit af8ce30

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed
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
@@ -11296,7 +11296,7 @@ _PyType_InitSlotDefs(PyInterpreterState *interp)
1129611296
pytype_slotdef *p;
1129711297
Py_ssize_t idx = 0;
1129811298
for (p = slotdefs; p->name_strobj; p++, idx++) {
11299-
assert (idx < 255);
11299+
assert(idx < 255);
1130011300

1130111301
if (PyDict_GetItemRef(cache, p->name_strobj, &bytearray) < 0) {
1130211302
goto error;
@@ -11317,11 +11317,11 @@ _PyType_InitSlotDefs(PyInterpreterState *interp)
1131711317
}
1131811318
}
1131911319

11320-
assert (PyByteArray_CheckExact(bytearray));
11320+
assert(PyByteArray_CheckExact(bytearray));
1132111321
uint8_t *data = (uint8_t *)PyByteArray_AS_STRING(bytearray);
1132211322

1132311323
data[0] += 1;
11324-
assert (data[0] < MAX_EQUIV);
11324+
assert(data[0] < MAX_EQUIV);
1132511325

1132611326
data[data[0]] = (uint8_t)idx;
1132711327

@@ -11330,9 +11330,9 @@ _PyType_InitSlotDefs(PyInterpreterState *interp)
1133011330

1133111331
memset(slotdefs_name_counts, 0, sizeof(slotdefs_name_counts));
1133211332

11333-
Py_ssize_t pos=0;
11334-
PyObject *key=NULL;
11335-
PyObject *value=NULL;
11333+
Py_ssize_t pos = 0;
11334+
PyObject *key = NULL;
11335+
PyObject *value = NULL;
1133611336
while (PyDict_Next(cache, &pos, &key, &value)) {
1133711337
uint8_t *data = (uint8_t *)PyByteArray_AS_STRING(value);
1133811338
uint8_t n = data[0];

0 commit comments

Comments
 (0)