pub fn compute_line_col(src: &[u8], offset: usize) -> (u32, u32)Expand description
Byte-offset → (line, column) translation over source bytes, for
consumers that compute node.line / Element.sourceline outside the
parser (e.g. the C-ABI incremental push parser).
Compute 1-based (line, col) for the given byte offset in src.
Called only when an error is being constructed. Uses memchr_iter to
count newlines and memrchr to find the start of the offending line, so
the scan is SIMD-accelerated even though it runs O(n). Total cost is
roughly equivalent to one extra pass over the prefix — fine in an error
path that fires at most once per parse.
The hot parsing path no longer updates a per-byte (line, col); instead
the parser tracks a single byte cursor (the offset in src) and we
translate to the human-friendly coordinate only when constructing the
error.