diff options
| author | Michael Woerister <michaelwoerister@posteo> | 2018-05-23 15:59:42 +0200 |
|---|---|---|
| committer | Michael Woerister <michaelwoerister@posteo> | 2018-06-27 14:00:34 +0200 |
| commit | 257d279fe47bbf3431c76f0942654c1bcf60d501 (patch) | |
| tree | b7230231778da7b5345f80ea6565c67ce9b14843 /src/libsyntax/codemap.rs | |
| parent | c20824323cf7ed6ad95cb8d7b780a7934927a753 (diff) | |
| download | rust-257d279fe47bbf3431c76f0942654c1bcf60d501.tar.gz rust-257d279fe47bbf3431c76f0942654c1bcf60d501.zip | |
Make FileMap::{lines, multibyte_chars, non_narrow_chars} non-mutable.
Diffstat (limited to 'src/libsyntax/codemap.rs')
| -rw-r--r-- | src/libsyntax/codemap.rs | 40 |
1 files changed, 16 insertions, 24 deletions
diff --git a/src/libsyntax/codemap.rs b/src/libsyntax/codemap.rs index 8e4b7660a1c..000f1607514 100644 --- a/src/libsyntax/codemap.rs +++ b/src/libsyntax/codemap.rs @@ -250,16 +250,7 @@ impl CodeMap { /// Creates a new filemap and sets its line information. /// This does not ensure that only one FileMap exists per file name. pub fn new_filemap_and_lines(&self, filename: &Path, src: &str) -> Lrc<FileMap> { - let fm = self.new_filemap(filename.to_owned().into(), src.to_owned()); - let mut byte_pos: u32 = fm.start_pos.0; - for line in src.lines() { - // register the start of this line - fm.next_line(BytePos(byte_pos)); - - // update byte_pos to include this line and the \n at the end - byte_pos += line.len() as u32 + 1; - } - fm + self.new_filemap(filename.to_owned().into(), src.to_owned()) } @@ -305,9 +296,9 @@ impl CodeMap { external_src: Lock::new(ExternalSource::AbsentOk), start_pos, end_pos, - lines: Lock::new(file_local_lines), - multibyte_chars: Lock::new(file_local_multibyte_chars), - non_narrow_chars: Lock::new(file_local_non_narrow_chars), + lines: file_local_lines, + multibyte_chars: file_local_multibyte_chars, + non_narrow_chars: file_local_non_narrow_chars, name_hash, }); @@ -345,21 +336,22 @@ impl CodeMap { match self.lookup_line(pos) { Ok(FileMapAndLine { fm: f, line: a }) => { let line = a + 1; // Line numbers start at 1 - let linebpos = (*f.lines.borrow())[a]; + let linebpos = f.lines[a]; let linechpos = self.bytepos_to_file_charpos(linebpos); let col = chpos - linechpos; let col_display = { - let non_narrow_chars = f.non_narrow_chars.borrow(); - let start_width_idx = non_narrow_chars + let start_width_idx = f + .non_narrow_chars .binary_search_by_key(&linebpos, |x| x.pos()) .unwrap_or_else(|x| x); - let end_width_idx = non_narrow_chars + let end_width_idx = f + .non_narrow_chars .binary_search_by_key(&pos, |x| x.pos()) .unwrap_or_else(|x| x); let special_chars = end_width_idx - start_width_idx; - let non_narrow: usize = - non_narrow_chars[start_width_idx..end_width_idx] + let non_narrow: usize = f + .non_narrow_chars[start_width_idx..end_width_idx] .into_iter() .map(|x| x.width()) .sum(); @@ -380,12 +372,12 @@ impl CodeMap { } Err(f) => { let col_display = { - let non_narrow_chars = f.non_narrow_chars.borrow(); - let end_width_idx = non_narrow_chars + let end_width_idx = f + .non_narrow_chars .binary_search_by_key(&pos, |x| x.pos()) .unwrap_or_else(|x| x); - let non_narrow: usize = - non_narrow_chars[0..end_width_idx] + let non_narrow: usize = f + .non_narrow_chars[0..end_width_idx] .into_iter() .map(|x| x.width()) .sum(); @@ -830,7 +822,7 @@ impl CodeMap { // The number of extra bytes due to multibyte chars in the FileMap let mut total_extra_bytes = 0; - for mbc in map.multibyte_chars.borrow().iter() { + for mbc in map.multibyte_chars.iter() { debug!("{}-byte char at {:?}", mbc.bytes, mbc.pos); if mbc.pos < bpos { // every character is at least one byte, so we only |
