From 68d61620ed812442ed85ebdcdc851f9440b3b84c Mon Sep 17 00:00:00 2001 From: "codeflash-ai[bot]" <148906541+codeflash-ai[bot]@users.noreply.github.com> Date: Fri, 20 Feb 2026 06:34:52 +0000 Subject: [PATCH 1/2] Optimize _byte_to_line_index The main optimization here is eliminating the `max(0, idx)` call by handling the edge case directly. Since `bisect_right` returns 0 when `byte_offset` is less than all elements, subtracting 1 gives -1, which we can catch with a simple comparison. This avoids the function call overhead of `max()`. --- codeflash/languages/java/instrumentation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/codeflash/languages/java/instrumentation.py b/codeflash/languages/java/instrumentation.py index f93f78b55..931d5a672 100644 --- a/codeflash/languages/java/instrumentation.py +++ b/codeflash/languages/java/instrumentation.py @@ -294,7 +294,7 @@ def _collect_calls(node, wrapper_bytes, body_bytes, prefix_len, func_name, analy def _byte_to_line_index(byte_offset: int, line_byte_starts: list[int]) -> int: """Map a byte offset in body_text to a body_lines index.""" idx = bisect.bisect_right(line_byte_starts, byte_offset) - 1 - return max(0, idx) + return 0 if idx < 0 else idx def _infer_array_cast_type(line: str) -> str | None: From 2ed9d896e19f4b854bbb876d9bc10289b3d20857 Mon Sep 17 00:00:00 2001 From: "claude[bot]" <41898282+claude[bot]@users.noreply.github.com> Date: Fri, 20 Feb 2026 06:37:15 +0000 Subject: [PATCH 2/2] style: auto-fix linting issues --- codeflash/languages/java/instrumentation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/codeflash/languages/java/instrumentation.py b/codeflash/languages/java/instrumentation.py index 931d5a672..5dabd0a81 100644 --- a/codeflash/languages/java/instrumentation.py +++ b/codeflash/languages/java/instrumentation.py @@ -294,7 +294,7 @@ def _collect_calls(node, wrapper_bytes, body_bytes, prefix_len, func_name, analy def _byte_to_line_index(byte_offset: int, line_byte_starts: list[int]) -> int: """Map a byte offset in body_text to a body_lines index.""" idx = bisect.bisect_right(line_byte_starts, byte_offset) - 1 - return 0 if idx < 0 else idx + return max(idx, 0) def _infer_array_cast_type(line: str) -> str | None: