summaryrefslogtreecommitdiffstats
path: root/Doc/c-api
diff options
context:
space:
mode:
authorMark Shannon <mark@hotpy.org>2023-05-21 13:45:48 (GMT)
committerGitHub <noreply@github.com>2023-05-21 13:45:48 (GMT)
commit93923793f602ea9117f13bfac8cbe01a864eeb01 (patch)
tree33657460417c68e16479212566385144a0d9d30a /Doc/c-api
parentab71acd67b5b09926498b8c7f855bdb28ac0ec2f (diff)
downloadcpython-93923793f602ea9117f13bfac8cbe01a864eeb01.zip
cpython-93923793f602ea9117f13bfac8cbe01a864eeb01.tar.gz
cpython-93923793f602ea9117f13bfac8cbe01a864eeb01.tar.bz2
GH-101291: Add low level, unstable API for pylong (GH-101685)
Co-authored-by: Petr Viktorin <encukou@gmail.com>
Diffstat (limited to 'Doc/c-api')
-rw-r--r--Doc/c-api/long.rst24
1 files changed, 24 insertions, 0 deletions
diff --git a/Doc/c-api/long.rst b/Doc/c-api/long.rst
index 4a71c89..5c1d026 100644
--- a/Doc/c-api/long.rst
+++ b/Doc/c-api/long.rst
@@ -322,3 +322,27 @@ distinguished from a number. Use :c:func:`PyErr_Occurred` to disambiguate.
with :c:func:`PyLong_FromVoidPtr`.
Returns ``NULL`` on error. Use :c:func:`PyErr_Occurred` to disambiguate.
+
+
+.. c:function:: int PyUnstable_Long_IsCompact(const PyLongObject* op)
+
+ Return 1 if *op* is compact, 0 otherwise.
+
+ This function makes it possible for performance-critical code to implement
+ a “fast path” for small integers. For compact values use
+ :c:func:`PyUnstable_Long_CompactValue`; for others fall back to a
+ :c:func:`PyLong_As* <PyLong_AsSize_t>` function or
+ :c:func:`calling <PyObject_CallMethod>` :meth:`int.to_bytes`.
+
+ The speedup is expected to be negligible for most users.
+
+ Exactly what values are considered compact is an implementation detail
+ and is subject to change.
+
+.. c:function:: Py_ssize_t PyUnstable_Long_CompactValue(const PyLongObject* op)
+
+ If *op* is compact, as determined by :c:func:`PyUnstable_Long_IsCompact`,
+ return its value.
+
+ Otherwise, the return value is undefined.
+