Skip to content

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

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

Closed
eddyb opened this issue Sep 2, 2017 · 2 comments
Closed

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

eddyb opened this issue Sep 2, 2017 · 2 comments
Labels
C-cleanup Category: PRs that clean code up or issues documenting cleanup.

Comments

@eddyb
Copy link
Member

eddyb commented Sep 2, 2017

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.

@eddyb eddyb added the C-cleanup Category: PRs that clean code up or issues documenting cleanup. label Sep 2, 2017
@wesleywiser
Copy link
Member

I think @michaelwoerister made these changes in #50997. @eddyb do you think this can be closed or is there still more to do?

@michaelwoerister
Copy link
Member

I think this should be pretty much fixed. Good catch, @wesleywiser!

@eddyb eddyb closed this as completed Sep 24, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-cleanup Category: PRs that clean code up or issues documenting cleanup.
Projects
None yet
Development

No branches or pull requests

3 participants