Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gh-107137: Add _PyTupleBuilder API to the internal C API #107139

Closed
wants to merge 1 commit into from

Commits on Jul 23, 2023

  1. pythongh-107137: Add _PyTupleBuilder API to the internal C API

    Add _PyTupleBuilder structure and functions:
    
    * _PyTupleBuilder_Init()
    * _PyTupleBuilder_Alloc()
    * _PyTupleBuilder_Append()
    * _PyTupleBuilder_AppendUnsafe()
    * _PyTupleBuilder_Finish()
    * _PyTupleBuilder_Dealloc()
    
    The builder tracks the size of the tuple and resize it in
    _PyTupleBuilder_Finish() if needed. Don't allocate empty tuple.
    Allocate an array of 16 objects on the stack to avoid allocating
    small tuple. _PyTupleBuilder_Append() overallocates the tuple by 25%
    to reduce the number of _PyTuple_Resize() calls.
    
    Do no track the temporary internal tuple by the GC before
    _PyTupleBuilder_Finish() creates the final complete and consistent
    tuple object.
    
    Use _PyTupleBuilder API in itertools batched_traverse(),
    PySequence_Tuple() and initialize_structseq_dict().
    
    Add also helper functions:
    
    * _PyTuple_ResizeNoTrack()
    * _PyTuple_NewNoTrack()
    vstinner committed Jul 23, 2023
    Configuration menu
    Copy the full SHA
    e55f80a View commit details
    Browse the repository at this point in the history