Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commite6091f8

Browse files
committed
gh-81381: Reduce allcoated size of PyType_GenericAlloc if possible
1 parent11f9932 commite6091f8

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Reduce the extra allocation size of:c:func:`PyType_GenericAlloc` except the
2+
type is if a subtype of 'type'.

‎Objects/typeobject.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1289,9 +1289,12 @@ PyObject *
12891289
_PyType_AllocNoTrack(PyTypeObject*type,Py_ssize_tnitems)
12901290
{
12911291
PyObject*obj;
1292-
constsize_tsize=_PyObject_VAR_SIZE(type,nitems+1);
1293-
/* note that we need to add one, for the sentinel */
1294-
1292+
size_textra=0;
1293+
if (type->tp_flags&Py_TPFLAGS_TYPE_SUBCLASS||type->tp_flags&Py_TPFLAGS_HAVE_VECTORCALL) {
1294+
/* note that we need to add one, for the sentinel */
1295+
extra=1;
1296+
}
1297+
constsize_tsize=_PyObject_VAR_SIZE(type,nitems+extra);
12951298
constsize_tpresize=_PyType_PreHeaderSize(type);
12961299
char*alloc=PyObject_Malloc(size+presize);
12971300
if (alloc==NULL) {
@@ -1309,7 +1312,7 @@ _PyType_AllocNoTrack(PyTypeObject *type, Py_ssize_t nitems)
13091312
_PyObject_Init(obj,type);
13101313
}
13111314
else {
1312-
_PyObject_InitVar((PyVarObject*)obj,type,nitems);
1315+
_PyObject_InitVar((PyVarObject*)obj,type,nitems+extra);
13131316
}
13141317
returnobj;
13151318
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp