Skip to content

Simplify and optimize FileMap's line/column mapping computation. #44264

Closed
@eddyb

Description

@eddyb

Right now this is done while lexing:

if old_ch_is_newline {
if self.save_new_lines_and_multibyte {
self.filemap.next_line(self.pos);
}
self.col = CharPos(0);
} else {
self.col = self.col + CharPos(1);
}
if new_ch_len > 1 {
if self.save_new_lines_and_multibyte {
self.filemap.record_multibyte_char(self.pos, new_ch_len);
}
}

While that may seem like it avoids going twice over the file contents, lexing is slow, while newline and non-width-1 (which is also improperly computed by means of multi-byte characters, instead of the unicode-width library) character finding can be optimized one way or another.

Cleaning this up would get rid of hacks such as the save_new_lines_and_multibyte flag in the code linked above and having to reimplement this in anything else using CodeMap outside of libsyntax.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-cleanupCategory: PRs that clean code up or issues documenting cleanup.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions