cpython/Include/internal
Cody Maloney 732224e113
gh-139871: Add bytearray.take_bytes([n]) to efficiently extract bytes (GH-140128)
Update `bytearray` to contain a `bytes` and provide a zero-copy path to
"extract" the `bytes`. This allows making several code paths more efficient.

This does not move any codepaths to make use of this new API. The documentation
changes include common code patterns which can be made more efficient with
this API.

---

When just changing `bytearray` to contain `bytes` I ran pyperformance on a
`--with-lto --enable-optimizations --with-static-libpython` build and don't see
any major speedups or slowdowns with this; all seems to be in the noise of
my machine (Generally changes under 5% or benchmarks that don't touch
bytes/bytearray).


Co-authored-by: Victor Stinner <vstinner@python.org>
Co-authored-by: Maurycy Pawłowski-Wieroński <5383+maurycy@users.noreply.github.com>
2025-11-13 13:19:44 +00:00
..
mimalloc Doc: More duplicate word fixes (GH-136299) 2025-07-11 21:18:47 +03:00
pycore_abstract.h gh-135763: AC: Implement `allow_negative for Py_ssize_t` (#138150) 2025-09-01 22:55:22 +01:00
pycore_asdl.h
pycore_ast.h gh-132661: Implement PEP 750 (#132662) 2025-04-30 11:46:41 +02:00
pycore_ast_state.h gh-132661: Implement PEP 750 (#132662) 2025-04-30 11:46:41 +02:00
pycore_atexit.h gh-131238: Remove pycore_lock.h includes (#131483) 2025-03-19 23:46:25 +00:00
pycore_audit.h
pycore_backoff.h GH-131798: Optimize cached class attributes and methods in the JIT (GH-134403) 2025-05-22 11:15:03 -04:00
pycore_bitutils.h
pycore_blocks_output_buffer.h gh-139877: Use PyBytesWriter in pycore_blocks_output_buffer.h (#139976) 2025-10-14 10:03:55 -07:00
pycore_brc.h gh-131238: Remove pycore_lock.h includes (#131483) 2025-03-19 23:46:25 +00:00
pycore_bytes_methods.h gh-71679: Share the repr implementation between bytes and bytearray (GH-138181) 2025-09-17 11:10:29 +03:00
pycore_bytesobject.h gh-139871: Add bytearray.take_bytes([n]) to efficiently extract bytes (GH-140128) 2025-11-13 13:19:44 +00:00
pycore_c_array.h gh-130080: move _Py_EnsureArrayLargeEnough to a separate header so it can be used outside of the compiler (#130930) 2025-03-13 16:02:58 +00:00
pycore_call.h gh-131776: Expose functions called from the interpreter loop via PyAPI_FUNC (#134242) 2025-09-17 08:04:02 -07:00
pycore_capsule.h
pycore_cell.h gh-123358: Use _PyStackRef in LOAD_DEREF (gh-130064) 2025-03-26 12:08:20 -04:00
pycore_ceval.h gh-140373: Correctly emit PY_UNWIND event when generator is closed (GH-140767) 2025-10-31 10:09:22 +00:00
pycore_ceval_state.h gh-131238: Remove pycore_lock.h includes (#131483) 2025-03-19 23:46:25 +00:00
pycore_code.h gh-140815: Fix faulthandler for invalid/freed frame (#140921) 2025-11-04 11:48:28 +01:00
pycore_codecs.h gh-131238: Remove pycore_lock.h includes (#131483) 2025-03-19 23:46:25 +00:00
pycore_compile.h gh-135801: Add the module parameter to compile() etc (GH-139652) 2025-11-13 13:21:32 +02:00
pycore_complexobject.h gh-128813: hide mixed-mode functions for complex arithmetic from C-API (#131703) 2025-04-22 14:18:18 +02:00
pycore_condvar.h gh-131082: Add missing guards for WIN32_LEAN_AND_MEAN (#131044) 2025-03-11 12:33:01 +01:00
pycore_context.h GH-131238: Core header refactor (GH-131250) 2025-03-17 09:19:04 +00:00
pycore_critical_section.h gh-133296: Publicly expose critical section API that accepts PyMutex (gh-135899) 2025-07-21 17:25:43 -04:00
pycore_crossinterp.h gh-132775: Clean Up Cross-Interpreter Error Handling (gh-135369) 2025-06-13 16:45:21 -06:00
pycore_crossinterp_data_registry.h gh-132775: Support Fallbacks in _PyObject_GetXIData() (gh-133482) 2025-05-21 07:23:48 -06:00
pycore_debug_offsets.h gh-135755: Make Py_MAX_SCRIPT_PATH_SIZE private (#138350) 2025-09-01 20:01:01 +01:00
pycore_descrobject.h
pycore_dict.h gh-125996: fix thread safety of collections.OrderedDict (#133734) 2025-10-13 22:55:07 +05:30
pycore_dict_state.h
pycore_dtoa.h GH-131238: Core header refactor (GH-131250) 2025-03-17 09:19:04 +00:00
pycore_emscripten_signal.h
pycore_emscripten_trampoline.h gh-132097: use a macro for semantically casting function pointers (#132406) 2025-04-18 12:24:34 +02:00
pycore_exceptions.h
pycore_faulthandler.h gh-127604: Add C stack dumps to faulthandler (#128159) 2025-04-21 20:48:02 +01:00
pycore_fileutils.h gh-131238: Use pycore_interp_structs.h header (#131481) 2025-03-19 23:13:25 +00:00
pycore_fileutils_windows.h
pycore_floatobject.h GH-131238: Core header refactor (GH-131250) 2025-03-17 09:19:04 +00:00
pycore_flowgraph.h
pycore_format.h
pycore_frame.h gh-130704: Strength reduce LOAD_FAST{_LOAD_FAST} (#130708) 2025-04-01 10:18:42 -07:00
pycore_freelist.h gh-140544: store pointer to interpreter state as a thread local for fast access (#140573) 2025-10-25 19:56:07 +05:30
pycore_freelist_state.h gh-129813, PEP 782: Add PyBytesWriter C API (#138822) 2025-09-12 13:41:59 +02:00
pycore_function.h gh-131776: Expose functions called from the interpreter loop via PyAPI_FUNC (#134242) 2025-09-17 08:04:02 -07:00
pycore_gc.h GH-139951: Fix major GC performance regression (GH-140262) 2025-10-21 15:22:15 +01:00
pycore_genobject.h gh-131776: Expose functions called from the interpreter loop via PyAPI_FUNC (#134242) 2025-09-17 08:04:02 -07:00
pycore_getopt.h
pycore_gil.h
pycore_global_objects.h GH-131238: Core header refactor (GH-131250) 2025-03-17 09:19:04 +00:00
pycore_global_objects_fini_generated.h gh-139817: Attribute __qualname__ is added to TypeAliasType (#139919) 2025-10-15 09:08:17 -07:00
pycore_global_strings.h gh-139817: Attribute __qualname__ is added to TypeAliasType (#139919) 2025-10-15 09:08:17 -07:00
pycore_hamt.h GH-131238: Core header refactor (GH-131250) 2025-03-17 09:19:04 +00:00
pycore_hashtable.h
pycore_import.h gh-81313: Add the math.integer module (PEP-791) (GH-133909) 2025-10-31 16:13:43 +02:00
pycore_importdl.h gh-141169: Re-raise exception from findfuncptr (GH-141349) 2025-11-11 13:52:13 +01:00
pycore_index_pool.h GH-131238: Core header refactor (GH-131250) 2025-03-17 09:19:04 +00:00
pycore_initconfig.h gh-130931: Add pycore_typedefs.h internal header (#131396) 2025-03-19 15:23:32 +01:00
pycore_instruction_sequence.h gh-130907: Treat all module-level annotations as conditional (#131550) 2025-04-28 06:10:28 -07:00
pycore_instruments.h gh-131776: Expose functions called from the interpreter loop via PyAPI_FUNC (#134242) 2025-09-17 08:04:02 -07:00
pycore_interp.h gh-131238: Remove includes from pycore_interp.h (#131495) 2025-03-20 11:35:23 +00:00
pycore_interp_structs.h gh-131253: free-threaded build support for pystats (gh-137189) 2025-11-03 11:36:37 -08:00
pycore_interpframe.h gh-140815: Fix faulthandler for invalid/freed frame (#140921) 2025-11-04 11:48:28 +01:00
pycore_interpframe_structs.h gh-131238: Add pycore_interpframe_structs.h header (#131553) 2025-03-21 17:19:47 +00:00
pycore_interpolation.h gh-132661: Implement PEP 750 (#132662) 2025-04-30 11:46:41 +02:00
pycore_intrinsics.h
pycore_jit.h GH-131498: Remove conditional stack effects (GH-131499) 2025-03-20 15:39:38 +00:00
pycore_list.h gh-100239: specialize BINARY_OP/SUBSCR for list-slice (#132626) 2025-05-01 10:28:52 +00:00
pycore_llist.h
pycore_lock.h gh-136759: rename lock.h to pylock.h (#137041) 2025-07-24 16:16:07 +05:30
pycore_long.h gh-129813, PEP 782: Use PyBytesWriter in _PyBytes_FormatEx() (#138839) 2025-09-15 12:23:36 +02:00
pycore_magic_number.h gh-138349: Fix crash when combining module-level annotation and listcomp (#138363) 2025-09-10 15:18:39 +02:00
pycore_memoryobject.h gh-132776: Revert Moving memoryview XIData Code to memoryobject.c (gh-132960) 2025-04-25 16:43:50 +00:00
pycore_mimalloc.h
pycore_modsupport.h gh-129594: Remove redundant check on varargs in _PyArg_CheckPositional (#129595) 2025-05-26 10:51:12 +02:00
pycore_moduleobject.h gh-141150: Don't rely on implicit conversion from void * to pointer in _PyModule… (#141147) 2025-11-06 07:16:56 -08:00
pycore_namespace.h
pycore_object.h gh-112075: Remove _PyObject_SetManagedDict() function (#139737) 2025-10-12 19:32:10 +02:00
pycore_object_alloc.h
pycore_object_deferred.h
pycore_object_stack.h
pycore_object_state.h
pycore_obmalloc.h
pycore_obmalloc_init.h
pycore_opcode_metadata.h gh-137883: Check the recursion limit for specialized keyword argument calls (GH-137887) 2025-08-19 09:53:38 +01:00
pycore_opcode_utils.h gh-132775: Unrevert "Add _PyCode_VerifyStateless()" (gh-133528) 2025-05-08 00:00:33 +00:00
pycore_optimizer.h gh-138050: [WIP] JIT - Streamline MAKE_WARM - move coldness check to executor creation (GH-138240) 2025-10-27 16:37:37 +00:00
pycore_parking_lot.h
pycore_parser.h gh-135801: Add the module parameter to compile() etc (GH-139652) 2025-11-13 13:21:32 +02:00
pycore_pathconfig.h
pycore_pyarena.h
pycore_pyatomic_ft_wrappers.h gh-137514: Add a free-threading wrapper for mutexes (GH-137515) 2025-08-07 11:24:50 -04:00
pycore_pybuffer.h
pycore_pyerrors.h gh-135801: Add the module parameter to compile() etc (GH-139652) 2025-11-13 13:21:32 +02:00
pycore_pyhash.h GH-131238: Core header refactor (GH-131250) 2025-03-17 09:19:04 +00:00
pycore_pylifecycle.h gh-136421: Load _datetime static types during interpreter initialization (GH-136583) 2025-07-21 13:47:26 -04:00
pycore_pymath.h gh-141004: soft-deprecate Py_INFINITY macro (#141033) 2025-11-12 13:44:49 +01:00
pycore_pymem.h gh-140815: Fix faulthandler for invalid/freed frame (#140921) 2025-11-04 11:48:28 +01:00
pycore_pymem_init.h
pycore_pystate.h gh-140544: fix build for including pycore_pystate.h when HAVE_THREAD_LOCAL is not defined (#140623) 2025-10-28 01:40:41 +05:30
pycore_pystats.h gh-131253: free-threaded build support for pystats (gh-137189) 2025-11-03 11:36:37 -08:00
pycore_pythonrun.h gh-135801: Add the module parameter to compile() etc (GH-139652) 2025-11-13 13:21:32 +02:00
pycore_pythread.h GH-131238: Core header refactor (GH-131250) 2025-03-17 09:19:04 +00:00
pycore_qsbr.h GH-133136: Revise QSBR to reduce excess memory held (gh-135473) 2025-06-25 00:06:32 -07:00
pycore_range.h
pycore_runtime.h gh-131238: Use pycore_interp_structs.h header (#131481) 2025-03-19 23:13:25 +00:00
pycore_runtime_init.h gh-131185: Use a proper thread-local for cached thread states (gh-132510) 2025-05-21 07:01:25 -06:00
pycore_runtime_init_generated.h gh-139817: Attribute __qualname__ is added to TypeAliasType (#139919) 2025-10-15 09:08:17 -07:00
pycore_runtime_structs.h gh-133059: Increase the small positive integer cache to 1024 (GH-133160) 2025-09-24 17:05:30 -04:00
pycore_semaphore.h gh-137433: Fix deadlock with stop-the-world and daemon threads (gh-137735) 2025-09-16 09:21:58 +01:00
pycore_setobject.h gh-130312: SET_ADD should not lock (#130136) 2025-03-21 15:58:32 -07:00
pycore_signal.h
pycore_sliceobject.h
pycore_stackref.h gh-131527: Stackref debug borrow checker (#140599) 2025-11-05 11:12:56 -08:00
pycore_stats.h gh-131253: free-threaded build support for pystats (gh-137189) 2025-11-03 11:36:37 -08:00
pycore_strhex.h
pycore_structs.h GH-131498: Cases generator: manage stacks automatically (GH-132074) 2025-04-04 17:59:36 +01:00
pycore_structseq.h
pycore_symtable.h gh-135801: Add the module parameter to compile() etc (GH-139652) 2025-11-13 13:21:32 +02:00
pycore_sysmodule.h gh-108512: Add and use new replacements for PySys_GetObject() (GH-111035) 2025-05-28 20:11:09 +03:00
pycore_template.h gh-132661: Implement PEP 750 (#132662) 2025-04-30 11:46:41 +02:00
pycore_time.h Remove internal _PyTime_AsLong() function (#141053) 2025-11-05 18:37:06 +01:00
pycore_token.h gh-132661: Implement PEP 750 (#132662) 2025-04-30 11:46:41 +02:00
pycore_traceback.h gh-125434: Display thread name in faulthandler on Windows (#140675) 2025-10-27 18:41:18 +01:00
pycore_tracemalloc.h
pycore_tstate.h gh-131253: free-threaded build support for pystats (gh-137189) 2025-11-03 11:36:37 -08:00
pycore_tuple.h gh-111489: Remove _PyTuple_FromArray() alias (#139973) 2025-10-11 22:58:14 +02:00
pycore_typedefs.h gh-130931: Add pycore_typedefs.h internal header (#131396) 2025-03-19 15:23:32 +01:00
pycore_typeobject.h gh-132042: Remove resolve_slotdups() to speedup class creation (#132156) 2025-10-03 11:58:00 +02:00
pycore_typevarobject.h
pycore_ucnhash.h
pycore_unicodectype.h gh-129117: Add unicodedata.isxidstart() function (#140269) 2025-10-30 10:18:12 +00:00
pycore_unicodeobject.h gh-139353: Add Objects/unicode_writer.c file (#139911) 2025-10-30 14:36:15 +01:00
pycore_unicodeobject_generated.h gh-139817: Attribute __qualname__ is added to TypeAliasType (#139919) 2025-10-15 09:08:17 -07:00
pycore_unionobject.h gh-105499: Merge typing.Union and types.UnionType (#105511) 2025-03-04 11:44:19 -08:00
pycore_uniqueid.h GH-131238: Core header refactor (GH-131250) 2025-03-17 09:19:04 +00:00
pycore_uop.h gh-137838: Move _PyUOpInstruction buffer to PyInterpreterState (gh-138918) 2025-09-17 18:50:16 +01:00
pycore_uop_ids.h GH-138378: Move globals-to-consts pass into main optimizer pass (GH-138379) 2025-09-18 10:09:59 +01:00
pycore_uop_metadata.h GH-138378: Move globals-to-consts pass into main optimizer pass (GH-138379) 2025-09-18 10:09:59 +01:00
pycore_warnings.h GH-131238: Core header refactor (GH-131250) 2025-03-17 09:19:04 +00:00
pycore_weakref.h gh-135607: remove null checking of weakref list in dealloc of extension modules and objects (#135614) 2025-06-30 11:14:31 +00:00