[C API] Add `PyList_AsTupleAndClear()` function
Maintainer antworten meist innerhalb von 1 Tag
Dieses Issue hat noch niemand übernommen.
- #161643 von @xixi-box — ohne Merge geschlossen
Bewertung
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Anfängerfreundlichkeit
- 25/100
Rechercherichtung
Start by reading the existing internal _PyList_AsTupleAndClear() implementation and the public C API declarations and tests; the issue names no file or test path. Check the linked PR for current work. Done means the function is exposed as a public C API and covered by tests for transferring list items into a tuple.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
Building a tuple when the size if known is advance is easy: allocate a new tuple with PyTuple_New(size) and then fill items using PyTuple_SetItem() or PyTuple_SET_ITEM().
Building a tuple when the final size is not known in advance is more complicated. It's possible to call _PyTuple_Resize() multiple time to resize the tuple. But it's more efficient to build a list, since the list is overallocated and so mutliple "resize" operations are more efficient.
The problem is that PyList_AsTuple() has to call Py_NewRef() on each time to create the tuple, and then call Py_DECREF() on each item when destroying the temporary list. I propose adding a new PyList_AsTupleAndClear() function to transfer items from the list to the tuple and so avoid the useless INCREF/DECREF dance.
PyList_AsTupleAndClear() should only be called when a temporary list is created in the same function and the list cannot be exposed to Python.
In fact, Python already has an internal _PyList_AsTupleAndClear() function, since it's the most efficient way to build a tuple from a list. I just propose to make the function public.
Linked PRs
- gh-161637
- Vorherrschende Sprache
- Python
- Sterne
- 78.2k
- Forks
- 36.6k
- Ø Merge
- 19 Std. 57 Min.
- Gemergte PRs (30 T.)
- 630
Entwicklungsumgebung
Startet den Dev-Container des Projekts im Browser, mit Ihrem eigenen GitHub-Konto.
- Kein Dockerfile und keine Docker-Compose-Datei
- Hat eine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus python/cpython
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
Maintainer antworten meist innerhalb von 1 Tag
-
stdlib type-bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 75/100
Maintainer antworten meist innerhalb von 1 Tag
-
extension-modules stdlib topic-XML type-bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 76/100
python/cpython#161807 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
-
stdlib type-feature
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
python/cpython#161788 · 7 Kommentare ·
Maintainer antworten meist innerhalb von 1 Tag
-
extension-modules topic-IO type-bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 75/100
Maintainer antworten meist innerhalb von 1 Tag
Ähnliche Issues
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 62/100
cpp-best-practices/project_validator#267 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
Project-N-E-K-O/N.E.K.O#3725 ·
Maintainer antworten meist innerhalb von 1 Tag
-
[Bug] Sending a Telegram message chain twice duplicates mentionsEvtl. vergeben @123XieC hat das heute übernommen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
AstrBotDevs/AstrBot#11125 ·
Maintainer antworten meist innerhalb von 1 Tag
-
backend bug priority: high
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
nooriegarg/ContribIQ#73 ·
Maintainer antworten meist innerhalb von 1 Tag
-
bug p3 security
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 68/100
amd/gaia#8197 · 2 Kommentare ·
Maintainer antworten meist innerhalb von 1 Tag