diff --git a/src/librustc/ich/impls_syntax.rs b/src/librustc/ich/impls_syntax.rs index 3a37c1c18c8d9..7fd8580b1673e 100644 --- a/src/librustc/ich/impls_syntax.rs +++ b/src/librustc/ich/impls_syntax.rs @@ -457,27 +457,21 @@ impl<'a> HashStable> for FileMap { src_hash.hash_stable(hcx, hasher); // We only hash the relative position within this filemap - lines.with_lock(|lines| { - lines.len().hash_stable(hcx, hasher); - for &line in lines.iter() { - stable_byte_pos(line, start_pos).hash_stable(hcx, hasher); - } - }); + lines.len().hash_stable(hcx, hasher); + for &line in lines.iter() { + stable_byte_pos(line, start_pos).hash_stable(hcx, hasher); + } // We only hash the relative position within this filemap - multibyte_chars.with_lock(|multibyte_chars| { - multibyte_chars.len().hash_stable(hcx, hasher); - for &char_pos in multibyte_chars.iter() { - stable_multibyte_char(char_pos, start_pos).hash_stable(hcx, hasher); - } - }); + multibyte_chars.len().hash_stable(hcx, hasher); + for &char_pos in multibyte_chars.iter() { + stable_multibyte_char(char_pos, start_pos).hash_stable(hcx, hasher); + } - non_narrow_chars.with_lock(|non_narrow_chars| { - non_narrow_chars.len().hash_stable(hcx, hasher); - for &char_pos in non_narrow_chars.iter() { - stable_non_narrow_char(char_pos, start_pos).hash_stable(hcx, hasher); - } - }); + non_narrow_chars.len().hash_stable(hcx, hasher); + for &char_pos in non_narrow_chars.iter() { + stable_non_narrow_char(char_pos, start_pos).hash_stable(hcx, hasher); + } } } diff --git a/src/librustc/ty/maps/on_disk_cache.rs b/src/librustc/ty/maps/on_disk_cache.rs index 9ca90a06c4e50..305915b19eb3d 100644 --- a/src/librustc/ty/maps/on_disk_cache.rs +++ b/src/librustc/ty/maps/on_disk_cache.rs @@ -654,7 +654,7 @@ impl<'a, 'tcx, 'x> SpecializedDecoder for CacheDecoder<'a, 'tcx, 'x> { let len = BytePos::decode(self)?; let file_lo = self.file_index_to_file(file_lo_index); - let lo = file_lo.lines.borrow()[line_lo - 1] + col_lo; + let lo = file_lo.lines[line_lo - 1] + col_lo; let hi = lo + len; let expn_info_tag = u8::decode(self)?; diff --git a/src/librustc_metadata/decoder.rs b/src/librustc_metadata/decoder.rs index 8af4649ed5f40..10f0f180567a0 100644 --- a/src/librustc_metadata/decoder.rs +++ b/src/librustc_metadata/decoder.rs @@ -1164,9 +1164,9 @@ impl<'a, 'tcx> CrateMetadata { src_hash, start_pos, end_pos, - lines, - multibyte_chars, - non_narrow_chars, + mut lines, + mut multibyte_chars, + mut non_narrow_chars, name_hash, .. } = filemap_to_import; @@ -1177,15 +1177,12 @@ impl<'a, 'tcx> CrateMetadata { // `CodeMap::new_imported_filemap()` will then translate those // coordinates to their new global frame of reference when the // offset of the FileMap is known. - let mut lines = lines.into_inner(); for pos in &mut lines { *pos = *pos - start_pos; } - let mut multibyte_chars = multibyte_chars.into_inner(); for mbc in &mut multibyte_chars { mbc.pos = mbc.pos - start_pos; } - let mut non_narrow_chars = non_narrow_chars.into_inner(); for swc in &mut non_narrow_chars { *swc = *swc - start_pos; } diff --git a/src/libsyntax/codemap.rs b/src/libsyntax/codemap.rs index fe8ce75a4b8ea..886f74a933ea8 100644 --- a/src/libsyntax/codemap.rs +++ b/src/libsyntax/codemap.rs @@ -211,8 +211,7 @@ impl CodeMap { } } - /// Creates a new filemap without setting its line information. If you don't - /// intend to set the line information yourself, you should use new_filemap_and_lines. + /// Creates a new filemap. /// This does not ensure that only one FileMap exists per file name. pub fn new_filemap(&self, filename: FileName, src: String) -> Lrc { let start_pos = self.next_start_pos(); @@ -247,22 +246,6 @@ impl CodeMap { filemap } - /// 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 { - 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 - } - - /// Allocates a new FileMap representing a source file from an external /// crate. The source code of such an "imported filemap" is not available, /// but we still know enough to generate accurate debuginfo location @@ -305,9 +288,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 +328,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 +364,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 +814,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 @@ -1028,51 +1012,16 @@ impl FilePathMapping { #[cfg(test)] mod tests { use super::*; - use std::borrow::Cow; use rustc_data_structures::sync::Lrc; - #[test] - fn t1 () { - let cm = CodeMap::new(FilePathMapping::empty()); - let fm = cm.new_filemap(PathBuf::from("blork.rs").into(), - "first line.\nsecond line".to_string()); - fm.next_line(BytePos(0)); - // Test we can get lines with partial line info. - assert_eq!(fm.get_line(0), Some(Cow::from("first line."))); - // TESTING BROKEN BEHAVIOR: line break declared before actual line break. - fm.next_line(BytePos(10)); - assert_eq!(fm.get_line(1), Some(Cow::from("."))); - fm.next_line(BytePos(12)); - assert_eq!(fm.get_line(2), Some(Cow::from("second line"))); - } - - #[test] - #[should_panic] - fn t2 () { - let cm = CodeMap::new(FilePathMapping::empty()); - let fm = cm.new_filemap(PathBuf::from("blork.rs").into(), - "first line.\nsecond line".to_string()); - // TESTING *REALLY* BROKEN BEHAVIOR: - fm.next_line(BytePos(0)); - fm.next_line(BytePos(10)); - fm.next_line(BytePos(2)); - } - fn init_code_map() -> CodeMap { let cm = CodeMap::new(FilePathMapping::empty()); - let fm1 = cm.new_filemap(PathBuf::from("blork.rs").into(), - "first line.\nsecond line".to_string()); - let fm2 = cm.new_filemap(PathBuf::from("empty.rs").into(), - "".to_string()); - let fm3 = cm.new_filemap(PathBuf::from("blork2.rs").into(), - "first line.\nsecond line".to_string()); - - fm1.next_line(BytePos(0)); - fm1.next_line(BytePos(12)); - fm2.next_line(fm2.start_pos); - fm3.next_line(fm3.start_pos); - fm3.next_line(fm3.start_pos + BytePos(12)); - + cm.new_filemap(PathBuf::from("blork.rs").into(), + "first line.\nsecond line".to_string()); + cm.new_filemap(PathBuf::from("empty.rs").into(), + "".to_string()); + cm.new_filemap(PathBuf::from("blork2.rs").into(), + "first line.\nsecond line".to_string()); cm } @@ -1125,26 +1074,10 @@ mod tests { fn init_code_map_mbc() -> CodeMap { let cm = CodeMap::new(FilePathMapping::empty()); // € is a three byte utf8 char. - let fm1 = - cm.new_filemap(PathBuf::from("blork.rs").into(), - "fir€st €€€€ line.\nsecond line".to_string()); - let fm2 = cm.new_filemap(PathBuf::from("blork2.rs").into(), - "first line€€.\n€ second line".to_string()); - - fm1.next_line(BytePos(0)); - fm1.next_line(BytePos(28)); - fm2.next_line(fm2.start_pos); - fm2.next_line(fm2.start_pos + BytePos(20)); - - fm1.record_multibyte_char(BytePos(3), 3); - fm1.record_multibyte_char(BytePos(9), 3); - fm1.record_multibyte_char(BytePos(12), 3); - fm1.record_multibyte_char(BytePos(15), 3); - fm1.record_multibyte_char(BytePos(18), 3); - fm2.record_multibyte_char(fm2.start_pos + BytePos(10), 3); - fm2.record_multibyte_char(fm2.start_pos + BytePos(13), 3); - fm2.record_multibyte_char(fm2.start_pos + BytePos(18), 3); - + cm.new_filemap(PathBuf::from("blork.rs").into(), + "fir€st €€€€ line.\nsecond line".to_string()); + cm.new_filemap(PathBuf::from("blork2.rs").into(), + "first line€€.\n€ second line".to_string()); cm } @@ -1196,7 +1129,7 @@ mod tests { let cm = CodeMap::new(FilePathMapping::empty()); let inputtext = "aaaaa\nbbbbBB\nCCC\nDDDDDddddd\neee\n"; let selection = " \n ~~\n~~~\n~~~~~ \n \n"; - cm.new_filemap_and_lines(Path::new("blork.rs"), inputtext); + cm.new_filemap(Path::new("blork.rs").to_owned().into(), inputtext.to_string()); let span = span_from_selection(inputtext, selection); // check that we are extracting the text we thought we were extracting @@ -1239,7 +1172,7 @@ mod tests { let inputtext = "bbbb BB\ncc CCC\n"; let selection1 = " ~~\n \n"; let selection2 = " \n ~~~\n"; - cm.new_filemap_and_lines(Path::new("blork.rs"), inputtext); + cm.new_filemap(Path::new("blork.rs").to_owned().into(), inputtext.to_owned()); let span1 = span_from_selection(inputtext, selection1); let span2 = span_from_selection(inputtext, selection2); diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index 146db632c07ba..6cff17dba01d9 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -1451,9 +1451,11 @@ impl<'a, 'b> Folder for InvocationCollector<'a, 'b> { match String::from_utf8(buf) { Ok(src) => { + let src_interned = Symbol::intern(&src); + // Add this input file to the code map to make it available as // dependency information - self.cx.codemap().new_filemap_and_lines(&filename, &src); + self.cx.codemap().new_filemap(filename.into(), src); let include_info = vec![ dummy_spanned(ast::NestedMetaItemKind::MetaItem( @@ -1461,7 +1463,7 @@ impl<'a, 'b> Folder for InvocationCollector<'a, 'b> { dummy_spanned(file)))), dummy_spanned(ast::NestedMetaItemKind::MetaItem( attr::mk_name_value_item_str(Ident::from_str("contents"), - dummy_spanned(Symbol::intern(&src))))), + dummy_spanned(src_interned)))), ]; let include_ident = Ident::from_str("include"); diff --git a/src/libsyntax/ext/source_util.rs b/src/libsyntax/ext/source_util.rs index d6dce63ea5e4b..669536f519ce3 100644 --- a/src/libsyntax/ext/source_util.rs +++ b/src/libsyntax/ext/source_util.rs @@ -150,11 +150,13 @@ pub fn expand_include_str(cx: &mut ExtCtxt, sp: Span, tts: &[tokenstream::TokenT }; match String::from_utf8(bytes) { Ok(src) => { + let interned_src = Symbol::intern(&src); + // Add this input file to the code map to make it available as // dependency information - cx.codemap().new_filemap_and_lines(&file, &src); + cx.codemap().new_filemap(file.into(), src); - base::MacEager::expr(cx.expr_str(sp, Symbol::intern(&src))) + base::MacEager::expr(cx.expr_str(sp, interned_src)) } Err(_) => { cx.span_err(sp, @@ -182,7 +184,7 @@ pub fn expand_include_bytes(cx: &mut ExtCtxt, sp: Span, tts: &[tokenstream::Toke Ok(..) => { // Add this input file to the code map to make it available as // dependency information, but don't enter it's contents - cx.codemap().new_filemap_and_lines(&file, ""); + cx.codemap().new_filemap(file.into(), "".to_string()); base::MacEager::expr(cx.expr_lit(sp, ast::LitKind::ByteStr(Lrc::new(bytes)))) } diff --git a/src/libsyntax/parse/lexer/mod.rs b/src/libsyntax/parse/lexer/mod.rs index a9dd234e1adc8..2fb2f578a0fbd 100644 --- a/src/libsyntax/parse/lexer/mod.rs +++ b/src/libsyntax/parse/lexer/mod.rs @@ -52,10 +52,6 @@ pub struct StringReader<'a> { pub filemap: Lrc, /// Stop reading src at this index. pub end_src_index: usize, - /// Whether to record new-lines and multibyte chars in filemap. - /// This is only necessary the first time a filemap is lexed. - /// If part of a filemap is being re-lexed, this should be set to false. - pub save_new_lines_and_multibyte: bool, // cached: peek_tok: token::Token, peek_span: Span, @@ -190,7 +186,6 @@ impl<'a> StringReader<'a> { ch: Some('\n'), filemap, end_src_index: src.len(), - save_new_lines_and_multibyte: true, // dummy values; not read peek_tok: token::Eof, peek_span: syntax_pos::DUMMY_SP, @@ -227,7 +222,6 @@ impl<'a> StringReader<'a> { let mut sr = StringReader::new_raw_internal(sess, begin.fm, None); // Seek the lexer to the right byte range. - sr.save_new_lines_and_multibyte = false; sr.next_pos = span.lo(); sr.end_src_index = sr.src_index(span.hi()); @@ -460,18 +454,6 @@ impl<'a> StringReader<'a> { let next_ch = char_at(&self.src, next_src_index); let next_ch_len = next_ch.len_utf8(); - if self.ch.unwrap() == '\n' { - if self.save_new_lines_and_multibyte { - self.filemap.next_line(self.next_pos); - } - } - if next_ch_len > 1 { - if self.save_new_lines_and_multibyte { - self.filemap.record_multibyte_char(self.next_pos, next_ch_len); - } - } - self.filemap.record_width(self.next_pos, next_ch); - self.ch = Some(next_ch); self.pos = self.next_pos; self.next_pos = self.next_pos + Pos::from_usize(next_ch_len); diff --git a/src/libsyntax/test_snippet.rs b/src/libsyntax/test_snippet.rs index 81dcc1998edd1..c7e4fbd1073d7 100644 --- a/src/libsyntax/test_snippet.rs +++ b/src/libsyntax/test_snippet.rs @@ -51,7 +51,7 @@ fn test_harness(file_text: &str, span_labels: Vec, expected_output: & let output = Arc::new(Mutex::new(Vec::new())); let code_map = Lrc::new(CodeMap::new(FilePathMapping::empty())); - code_map.new_filemap_and_lines(Path::new("test.rs"), &file_text); + code_map.new_filemap(Path::new("test.rs").to_owned().into(), file_text.to_owned()); let primary_span = make_span(&file_text, &span_labels[0].start, &span_labels[0].end); let mut msp = MultiSpan::from_span(primary_span); diff --git a/src/libsyntax_pos/lib.rs b/src/libsyntax_pos/lib.rs index 17163576901eb..aee3b67fd023b 100644 --- a/src/libsyntax_pos/lib.rs +++ b/src/libsyntax_pos/lib.rs @@ -782,11 +782,11 @@ pub struct FileMap { /// The end position of this source in the CodeMap pub end_pos: BytePos, /// Locations of lines beginnings in the source code - pub lines: Lock>, + pub lines: Vec, /// Locations of multi-byte characters in the source code - pub multibyte_chars: Lock>, + pub multibyte_chars: Vec, /// Width of characters that are not narrow in the source code - pub non_narrow_chars: Lock>, + pub non_narrow_chars: Vec, /// A hash of the filename, used for speeding up the incr. comp. hashing. pub name_hash: u128, } @@ -800,7 +800,7 @@ impl Encodable for FileMap { s.emit_struct_field("start_pos", 4, |s| self.start_pos.encode(s))?; s.emit_struct_field("end_pos", 5, |s| self.end_pos.encode(s))?; s.emit_struct_field("lines", 6, |s| { - let lines = self.lines.borrow(); + let lines = &self.lines[..]; // store the length s.emit_u32(lines.len() as u32)?; @@ -846,10 +846,10 @@ impl Encodable for FileMap { Ok(()) })?; s.emit_struct_field("multibyte_chars", 7, |s| { - (*self.multibyte_chars.borrow()).encode(s) + self.multibyte_chars.encode(s) })?; s.emit_struct_field("non_narrow_chars", 8, |s| { - (*self.non_narrow_chars.borrow()).encode(s) + self.non_narrow_chars.encode(s) })?; s.emit_struct_field("name_hash", 9, |s| { self.name_hash.encode(s) @@ -917,9 +917,9 @@ impl Decodable for FileMap { src: None, src_hash, external_src: Lock::new(ExternalSource::AbsentOk), - lines: Lock::new(lines), - multibyte_chars: Lock::new(multibyte_chars), - non_narrow_chars: Lock::new(non_narrow_chars), + lines, + multibyte_chars, + non_narrow_chars, name_hash, }) }) @@ -952,6 +952,9 @@ impl FileMap { }; let end_pos = start_pos.to_usize() + src.len(); + let (lines, multibyte_chars, non_narrow_chars) = + Self::find_newlines_and_special_chars(&src[..], start_pos); + FileMap { name, name_was_remapped, @@ -962,34 +965,81 @@ impl FileMap { external_src: Lock::new(ExternalSource::Unneeded), start_pos, end_pos: Pos::from_usize(end_pos), - lines: Lock::new(Vec::new()), - multibyte_chars: Lock::new(Vec::new()), - non_narrow_chars: Lock::new(Vec::new()), + lines, + multibyte_chars, + non_narrow_chars, name_hash, } } - /// EFFECT: register a start-of-line offset in the - /// table of line-beginnings. - /// UNCHECKED INVARIANT: these offsets must be added in the right - /// order and must be in the right places; there is shared knowledge - /// about what ends a line between this file and parse.rs - /// WARNING: pos param here is the offset relative to start of CodeMap, - /// and CodeMap will append a newline when adding a filemap without a newline at the end, - /// so the safe way to call this is with value calculated as - /// filemap.start_pos + newline_offset_relative_to_the_start_of_filemap. - pub fn next_line(&self, pos: BytePos) { - // the new charpos must be > the last one (or it's the first one). - let mut lines = self.lines.borrow_mut(); - let line_len = lines.len(); - assert!(line_len == 0 || ((*lines)[line_len - 1] < pos)); - lines.push(pos); + fn find_newlines_and_special_chars(src: &str, filemap_start_pos: BytePos) + -> (Vec, Vec, Vec) { + + let mut index = 0; + let mut lines = vec![filemap_start_pos]; + let mut multibyte_chars = vec![]; + let mut non_narrow_chars = vec![]; + + while index < src.len() { + let byte_pos = BytePos::from_usize(index) + filemap_start_pos; + let byte = src.as_bytes()[index]; + + if byte.is_ascii() { + match byte { + b'\n' => { + lines.push(byte_pos + BytePos(1)); + } + b'\t' => { + // Tabs will consume 4 columns. + non_narrow_chars.push(NonNarrowChar::new(byte_pos, 4)); + } + c => if c.is_ascii_control() { + // Assume control characters are zero width. + non_narrow_chars.push(NonNarrowChar::new(byte_pos, 0)); + } + } + + index += 1; + } else { + let c = (&src[index..]).chars().next().unwrap(); + let c_len = c.len_utf8(); + + if c_len > 1 { + assert!(c_len >=2 && c_len <= 4); + let mbc = MultiByteChar { + pos: byte_pos, + bytes: c_len, + }; + multibyte_chars.push(mbc); + } + + // Assume control characters are zero width. + // FIXME: How can we decide between `width` and `width_cjk`? + let c_width = unicode_width::UnicodeWidthChar::width(c).unwrap_or(0); + + if c_width != 1 { + non_narrow_chars.push(NonNarrowChar::new(byte_pos, c_width)); + } + + index += c_len; + } + } + + // The loop above optimistically registers a new line *after* each of \n + // it encounters. If that point is already outside the filemap, remove + // it again. + if let Some(&last_line_start) = lines.last() { + if last_line_start == filemap_start_pos + BytePos::from_usize(src.len()) { + lines.pop(); + } + } + + (lines, multibyte_chars, non_narrow_chars) } /// Return the BytePos of the beginning of the current line. pub fn line_begin_pos(&self) -> BytePos { - let lines = self.lines.borrow(); - match lines.last() { + match self.lines.last() { Some(&line_pos) => line_pos, None => self.start_pos, } @@ -1043,8 +1093,7 @@ impl FileMap { } let begin = { - let lines = self.lines.borrow(); - let line = if let Some(line) = lines.get(line_number) { + let line = if let Some(line) = self.lines.get(line_number) { line } else { return None; @@ -1062,35 +1111,6 @@ impl FileMap { } } - pub fn record_multibyte_char(&self, pos: BytePos, bytes: usize) { - assert!(bytes >=2 && bytes <= 4); - let mbc = MultiByteChar { - pos, - bytes, - }; - self.multibyte_chars.borrow_mut().push(mbc); - } - - #[inline] - pub fn record_width(&self, pos: BytePos, ch: char) { - let width = match ch { - '\t' => - // Tabs will consume 4 columns. - 4, - '\n' => - // Make newlines take one column so that displayed spans can point them. - 1, - ch => - // Assume control characters are zero width. - // FIXME: How can we decide between `width` and `width_cjk`? - unicode_width::UnicodeWidthChar::width(ch).unwrap_or(0), - }; - // Only record non-narrow characters. - if width != 1 { - self.non_narrow_chars.borrow_mut().push(NonNarrowChar::new(pos, width)); - } - } - pub fn is_real_file(&self) -> bool { self.name.is_real() } @@ -1103,7 +1123,7 @@ impl FileMap { self.end_pos.0 - self.start_pos.0 } pub fn count_lines(&self) -> usize { - self.lines.borrow().len() + self.lines.len() } /// Find the line containing the given position. The return value is the @@ -1111,13 +1131,12 @@ impl FileMap { /// number. If the filemap is empty or the position is located before the /// first line, None is returned. pub fn lookup_line(&self, pos: BytePos) -> Option { - let lines = self.lines.borrow(); - if lines.len() == 0 { + if self.lines.len() == 0 { return None; } - let line_index = lookup_line(&lines[..], pos); - assert!(line_index < lines.len() as isize); + let line_index = lookup_line(&self.lines[..], pos); + assert!(line_index < self.lines.len() as isize); if line_index >= 0 { Some(line_index as usize) } else { @@ -1130,12 +1149,11 @@ impl FileMap { return (self.start_pos, self.end_pos); } - let lines = self.lines.borrow(); - assert!(line_index < lines.len()); - if line_index == (lines.len() - 1) { - (lines[line_index], self.end_pos) + assert!(line_index < self.lines.len()); + if line_index == (self.lines.len() - 1) { + (self.lines[line_index], self.end_pos) } else { - (lines[line_index], lines[line_index + 1]) + (self.lines[line_index], self.lines[line_index + 1]) } }