summaryrefslogtreecommitdiffstats
path: root/Include
diff options
context:
space:
mode:
authorMark Shannon <mark@hotpy.org>2022-06-22 15:32:02 (GMT)
committerGitHub <noreply@github.com>2022-06-22 15:32:02 (GMT)
commit3ece6e6feb44b334cd759ead970e877bbd126892 (patch)
tree96846029de1a3123d7fd01f67df0e5597171955a /Include
parent8c2af4907133d4a235cce73231fab723653d6429 (diff)
downloadcpython-3ece6e6feb44b334cd759ead970e877bbd126892.zip
cpython-3ece6e6feb44b334cd759ead970e877bbd126892.tar.gz
cpython-3ece6e6feb44b334cd759ead970e877bbd126892.tar.bz2
[3.11] GH-93516: Backport GH-93769: Speedup line number checks when tracing (GH-94127)
Co-authored-by: Pablo Galindo <pablogsal@gmail.com>
Diffstat (limited to 'Include')
-rw-r--r--Include/cpython/code.h4
-rw-r--r--Include/internal/pycore_code.h29
2 files changed, 32 insertions, 1 deletions
diff --git a/Include/cpython/code.h b/Include/cpython/code.h
index ba7324b..d7c9aee 100644
--- a/Include/cpython/code.h
+++ b/Include/cpython/code.h
@@ -62,7 +62,8 @@ typedef uint16_t _Py_CODEUNIT;
PyObject *co_exceptiontable; /* Byte string encoding exception handling \
table */ \
int co_flags; /* CO_..., see below */ \
- int co_warmup; /* Warmup counter for quickening */ \
+ short co_warmup; /* Warmup counter for quickening */ \
+ short _co_linearray_entry_size; /* Size of each entry in _co_linearray */ \
\
/* The rest are not so impactful on performance. */ \
int co_argcount; /* #arguments, except *args */ \
@@ -88,6 +89,7 @@ typedef uint16_t _Py_CODEUNIT;
PyObject *co_qualname; /* unicode (qualname, for reference) */ \
PyObject *co_linetable; /* bytes object that holds location info */ \
PyObject *co_weakreflist; /* to support weakrefs to code objects */ \
+ char *_co_linearray; /* array of line offsets */ \
/* Scratch space for extra data relating to the code object. \
Type is a void* to keep the format private in codeobject.c to force \
people to go through the proper APIs. */ \
diff --git a/Include/internal/pycore_code.h b/Include/internal/pycore_code.h
index e11d1f0..551b9c0 100644
--- a/Include/internal/pycore_code.h
+++ b/Include/internal/pycore_code.h
@@ -475,6 +475,35 @@ write_location_entry_start(uint8_t *ptr, int code, int length)
}
+/* Line array cache for tracing */
+
+extern int _PyCode_CreateLineArray(PyCodeObject *co);
+
+static inline int
+_PyCode_InitLineArray(PyCodeObject *co)
+{
+ if (co->_co_linearray) {
+ return 0;
+ }
+ return _PyCode_CreateLineArray(co);
+}
+
+static inline int
+_PyCode_LineNumberFromArray(PyCodeObject *co, int index)
+{
+ assert(co->_co_linearray != NULL);
+ assert(index >= 0);
+ assert(index < Py_SIZE(co));
+ if (co->_co_linearray_entry_size == 2) {
+ return ((int16_t *)co->_co_linearray)[index];
+ }
+ else {
+ assert(co->_co_linearray_entry_size == 4);
+ return ((int32_t *)co->_co_linearray)[index];
+ }
+}
+
+
#ifdef __cplusplus
}
#endif