@@ -21,6 +21,7 @@ source code snippets, etc.
21
21
22
22
*/
23
23
24
+ use std:: cell:: RefCell ;
24
25
use std:: cmp;
25
26
use extra:: serialize:: { Encodable , Decodable , Encoder , Decoder } ;
26
27
@@ -220,7 +221,7 @@ pub struct FileMap {
220
221
/// The start position of this source in the CodeMap
221
222
start_pos : BytePos ,
222
223
/// Locations of lines beginnings in the source code
223
- lines : @ mut ~[ BytePos ] ,
224
+ lines : RefCell < ~[ BytePos ] > ,
224
225
/// Locations of multi-byte characters in the source code
225
226
multibyte_chars : @mut ~[ MultiByteChar ] ,
226
227
}
@@ -233,14 +234,16 @@ impl FileMap {
233
234
// about what ends a line between this file and parse.rs
234
235
pub fn next_line ( & self , pos : BytePos ) {
235
236
// 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) ;
239
241
}
240
242
241
243
// get a line from the list of pre-computed line-beginnings
242
244
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 ;
244
247
let begin = begin. to_uint ( ) ;
245
248
let slice = self . src . slice_from ( begin) ;
246
249
match slice. find ( '\n' ) {
@@ -296,7 +299,7 @@ impl CodeMap {
296
299
let filemap = @FileMap {
297
300
name : filename, substr : substr, src : src,
298
301
start_pos : Pos :: from_uint ( start_pos) ,
299
- lines : @ mut ~[ ] ,
302
+ lines : RefCell :: new ( ~[ ] ) ,
300
303
multibyte_chars : @mut ~[ ] ,
301
304
} ;
302
305
@@ -421,11 +424,11 @@ impl CodeMap {
421
424
let idx = self . lookup_filemap_idx ( pos) ;
422
425
let f = self . files [ idx] ;
423
426
let mut a = 0 u;
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 ( ) ;
426
429
while b - a > 1 u {
427
430
let m = ( a + b) / 2 u;
428
- if lines[ m] > pos { b = m; } else { a = m; }
431
+ if lines. get ( ) [ m] > pos { b = m; } else { a = m; }
429
432
}
430
433
return FileMapAndLine { fm : f, line : a} ;
431
434
}
@@ -434,7 +437,8 @@ impl CodeMap {
434
437
let FileMapAndLine { fm : f, line : a} = self . lookup_line ( pos) ;
435
438
let line = a + 1 u; // Line numbers start at 1
436
439
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] ;
438
442
let linechpos = self . bytepos_to_local_charpos ( linebpos) ;
439
443
debug ! ( "codemap: byte pos {:?} is on the line at byte pos {:?}" ,
440
444
pos, linebpos) ;
0 commit comments