Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

GH-127953: Make line number lookup O(1) regardless of the size of the code object #128350

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

Merged
merged 7 commits into from
Jan 21, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Address review comments
  • Loading branch information
markshannon committed Jan 3, 2025
commit 9ea88c0133af02e90492ad7049baf6e0ecc04950
16 changes: 7 additions & 9 deletions 16 Python/instrumentation.c
Original file line number Diff line number Diff line change
Expand Up @@ -279,18 +279,16 @@ get_events(_Py_GlobalMonitors *m, int tool_id)
return result;
}

/* Line delta.
* Variable sized int. Most significant byte first.
* if line_delta == NO_LINE:
* line = None
* else:
* line = first_line + line_delta
*/

/* Module code can have line 0, even though modules start at line 1,
* so -1 is a legal delta. */
#define NO_LINE (-2)

/* Returns the line delta. Defined as:
* if line is None:
* line_delta = NO_LINE
* else:
* line_delta = line - first_line
*/
static int
compute_line_delta(PyCodeObject *code, int line)
{
Expand Down Expand Up @@ -369,7 +367,7 @@ set_line_delta(_PyCoLineInstrumentationData *line_data, int index, int line_delt
assert(line_delta >= NO_LINE);
uint32_t adjusted = line_delta - NO_LINE;
uint8_t *ptr = &line_data->data[index*line_data->bytes_per_entry+1];
assert(line_data->bytes_per_entry > 2 || adjusted < 256);
assert(adjusted < (1ULL << (line_data->bytes_per_entry*8)));
gaogaotiantian marked this conversation as resolved.
Show resolved Hide resolved
if (line_data->bytes_per_entry > 2) {
if (line_data->bytes_per_entry > 3) {
if (line_data->bytes_per_entry > 4) {
Expand Down
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.