summaryrefslogtreecommitdiff
path: root/Include/internal/pycore_code.h
diff options
context:
space:
mode:
authorMark Shannon <mark@hotpy.org>2022-06-20 13:00:42 +0100
committerGitHub <noreply@github.com>2022-06-20 13:00:42 +0100
commitab0e60101637b7cf47f3cc95813996791e7118c4 (patch)
treec0590854ab9e9137c872f0789763d7bb07151fb0 /Include/internal/pycore_code.h
parent45e62a2bc1c0000e2e9b613fff6bebf2c26fcb93 (diff)
downloadcpython-git-ab0e60101637b7cf47f3cc95813996791e7118c4.tar.gz
GH-93516: Speedup line number checks when tracing. (GH-93763)
* Use a lookup table to reduce overhead of getting line numbers during tracing.
Diffstat (limited to 'Include/internal/pycore_code.h')
-rw-r--r--Include/internal/pycore_code.h29
1 files changed, 29 insertions, 0 deletions
diff --git a/Include/internal/pycore_code.h b/Include/internal/pycore_code.h
index 805c82483e..bb82d9fb9c 100644
--- a/Include/internal/pycore_code.h
+++ b/Include/internal/pycore_code.h
@@ -461,6 +461,35 @@ adaptive_counter_backoff(uint16_t counter) {
}
+/* 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