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

gh-81381: Reduce allocated size of PyType_GenericAlloc if possible#100855

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed
corona10 wants to merge1 commit intopython:mainfromcorona10:gh-81381
Closed
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
Reduce the extra allocation size of :c:func:`PyType_GenericAlloc` except the
type is if a subtype of 'type'.
11 changes: 7 additions & 4 deletionsObjects/typeobject.c
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -1289,9 +1289,12 @@ PyObject *
_PyType_AllocNoTrack(PyTypeObject *type, Py_ssize_t nitems)
{
PyObject *obj;
const size_t size = _PyObject_VAR_SIZE(type, nitems+1);
/* note that we need to add one, for the sentinel */

size_t extra = 0;
if (type->tp_flags & Py_TPFLAGS_TYPE_SUBCLASS || type->tp_flags & Py_TPFLAGS_HAVE_VECTORCALL) {
/* note that we need to add one, for the sentinel */
extra = 1;
}
const size_t size = _PyObject_VAR_SIZE(type, nitems + extra);
const size_t presize = _PyType_PreHeaderSize(type);
char *alloc = PyObject_Malloc(size + presize);
if (alloc == NULL) {
Expand All@@ -1309,7 +1312,7 @@ _PyType_AllocNoTrack(PyTypeObject *type, Py_ssize_t nitems)
_PyObject_Init(obj, type);
}
else {
_PyObject_InitVar((PyVarObject *)obj, type, nitems);
_PyObject_InitVar((PyVarObject *)obj, type, nitems + extra);
}
return obj;
}
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp