Skip to content

Commit 1f3d319

Browse files
committed
---
yaml --- r: 97396 b: refs/heads/dist-snap c: 27cc3d2 h: refs/heads/master v: v3
1 parent 7089f83 commit 1f3d319

File tree

3 files changed

+17
-12
lines changed

3 files changed

+17
-12
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ refs/heads/try: c274a6888410ce3e357e014568b43310ed787d36
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c
9-
refs/heads/dist-snap: ada9150abf26912478aa6f613602f8ac7ba135e5
9+
refs/heads/dist-snap: 27cc3d203baf219ae06596e9ac44f0c394024bb5
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
1212
refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0

branches/dist-snap/src/libsyntax/codemap.rs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ source code snippets, etc.
2121
2222
*/
2323

24+
use std::cell::RefCell;
2425
use std::cmp;
2526
use extra::serialize::{Encodable, Decodable, Encoder, Decoder};
2627

@@ -220,7 +221,7 @@ pub struct FileMap {
220221
/// The start position of this source in the CodeMap
221222
start_pos: BytePos,
222223
/// Locations of lines beginnings in the source code
223-
lines: @mut ~[BytePos],
224+
lines: RefCell<~[BytePos]>,
224225
/// Locations of multi-byte characters in the source code
225226
multibyte_chars: @mut ~[MultiByteChar],
226227
}
@@ -233,14 +234,16 @@ impl FileMap {
233234
// about what ends a line between this file and parse.rs
234235
pub fn next_line(&self, pos: BytePos) {
235236
// the new charpos must be > the last one (or it's the first one).
236-
let lines = &mut *self.lines;
237-
assert!((lines.len() == 0) || (lines[lines.len() - 1] < pos))
238-
lines.push(pos);
237+
let mut lines = self.lines.borrow_mut();;
238+
let line_len = lines.get().len();
239+
assert!(line_len == 0 || (lines.get()[line_len - 1] < pos))
240+
lines.get().push(pos);
239241
}
240242

241243
// get a line from the list of pre-computed line-beginnings
242244
pub fn get_line(&self, line: int) -> ~str {
243-
let begin: BytePos = self.lines[line] - self.start_pos;
245+
let mut lines = self.lines.borrow_mut();
246+
let begin: BytePos = lines.get()[line] - self.start_pos;
244247
let begin = begin.to_uint();
245248
let slice = self.src.slice_from(begin);
246249
match slice.find('\n') {
@@ -296,7 +299,7 @@ impl CodeMap {
296299
let filemap = @FileMap {
297300
name: filename, substr: substr, src: src,
298301
start_pos: Pos::from_uint(start_pos),
299-
lines: @mut ~[],
302+
lines: RefCell::new(~[]),
300303
multibyte_chars: @mut ~[],
301304
};
302305

@@ -421,11 +424,11 @@ impl CodeMap {
421424
let idx = self.lookup_filemap_idx(pos);
422425
let f = self.files[idx];
423426
let mut a = 0u;
424-
let lines = &*f.lines;
425-
let mut b = lines.len();
427+
let mut lines = f.lines.borrow_mut();
428+
let mut b = lines.get().len();
426429
while b - a > 1u {
427430
let m = (a + b) / 2u;
428-
if lines[m] > pos { b = m; } else { a = m; }
431+
if lines.get()[m] > pos { b = m; } else { a = m; }
429432
}
430433
return FileMapAndLine {fm: f, line: a};
431434
}
@@ -434,7 +437,8 @@ impl CodeMap {
434437
let FileMapAndLine {fm: f, line: a} = self.lookup_line(pos);
435438
let line = a + 1u; // Line numbers start at 1
436439
let chpos = self.bytepos_to_local_charpos(pos);
437-
let linebpos = f.lines[a];
440+
let mut lines = f.lines.borrow_mut();
441+
let linebpos = lines.get()[a];
438442
let linechpos = self.bytepos_to_local_charpos(linebpos);
439443
debug!("codemap: byte pos {:?} is on the line at byte pos {:?}",
440444
pos, linebpos);

branches/dist-snap/src/libsyntax/ext/source_util.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use parse;
1919
use parse::token::{get_ident_interner};
2020
use print::pprust;
2121

22+
use std::cell::RefCell;
2223
use std::io;
2324
use std::io::File;
2425
use std::str;
@@ -113,7 +114,7 @@ pub fn expand_include_str(cx: &mut ExtCtxt, sp: Span, tts: &[ast::token_tree])
113114
substr: codemap::FssNone,
114115
src: s,
115116
start_pos: codemap::BytePos(0),
116-
lines: @mut ~[],
117+
lines: RefCell::new(~[]),
117118
multibyte_chars: @mut ~[],
118119
});
119120
base::MRExpr(cx.expr_str(sp, s))

0 commit comments

Comments
 (0)