-
-
Notifications
You must be signed in to change notification settings - Fork 930
Closed
Labels
A-transformerArea - Transformer / TranspilerArea - Transformer / TranspilerC-bugCategory - BugCategory - BugC-performanceCategory - Solution not expected to change functional behavior, only performanceCategory - Solution not expected to change functional behavior, only performance
Description
oxc/crates/oxc_transformer/src/react/utils.rs
Lines 3 to 19 in a96866d
| /// Get line and column from offset and source text. | |
| /// | |
| /// Line number starts at 1. | |
| /// Column number is in UTF-16 characters, and starts at 1. | |
| /// | |
| /// This matches Babel's output. | |
| pub fn get_line_column(offset: u32, source_text: &str) -> (usize, usize) { | |
| let offset = offset as usize; | |
| let rope = Rope::from_str(source_text); | |
| // Get line number and byte offset of start of line | |
| let line_index = rope.byte_to_line(offset); | |
| let line_offset = rope.line_to_byte(line_index); | |
| // Get column number | |
| let column_index = source_text[line_offset..offset].encode_utf16().count(); | |
| // line and column are zero-indexed, but we want 1-indexed | |
| (line_index + 1, column_index + 1) | |
| } |
oxc/crates/oxc_language_server/src/linter.rs
Lines 373 to 381 in 2514cc9
| fn offset_to_position(offset: usize, source_text: &str) -> Option<Position> { | |
| let rope = Rope::from_str(source_text); | |
| let line = rope.try_byte_to_line(offset).ok()?; | |
| let first_char_of_line = rope.try_line_to_char(line).ok()?; | |
| // Original offset is byte, but Rope uses char offset | |
| let offset = rope.try_byte_to_char(offset).ok()?; | |
| let column = offset - first_char_of_line; | |
| Some(Position::new(line as u32, column as u32)) | |
| } |
Rope::from_str(source_text) is too expensive.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
A-transformerArea - Transformer / TranspilerArea - Transformer / TranspilerC-bugCategory - BugCategory - BugC-performanceCategory - Solution not expected to change functional behavior, only performanceCategory - Solution not expected to change functional behavior, only performance
Type
Fields
Give feedbackPriority
None yet
