Skip to content

Commit 00661aa

Browse files
committed
Preserve SourceMap's vector allocation when invalidating spans
1 parent b1e45d1 commit 00661aa

File tree

1 file changed

+7
-15
lines changed

1 file changed

+7
-15
lines changed

src/fallback.rs

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -320,31 +320,23 @@ impl Debug for SourceFile {
320320
}
321321
}
322322

323-
#[cfg(all(span_locations, not(fuzzing)))]
324-
fn dummy_file() -> FileInfo {
325-
FileInfo {
326-
source_text: String::new(),
327-
span: Span { lo: 0, hi: 0 },
328-
lines: vec![0],
329-
char_index_to_byte_offset: BTreeMap::new(),
330-
}
331-
}
332-
333323
#[cfg(all(span_locations, not(fuzzing)))]
334324
thread_local! {
335325
static SOURCE_MAP: RefCell<SourceMap> = RefCell::new(SourceMap {
336326
// Start with a single dummy file which all call_site() and def_site()
337327
// spans reference.
338-
files: vec![dummy_file()],
328+
files: vec![FileInfo {
329+
source_text: String::new(),
330+
span: Span { lo: 0, hi: 0 },
331+
lines: vec![0],
332+
char_index_to_byte_offset: BTreeMap::new(),
333+
}],
339334
});
340335
}
341336

342337
#[cfg(all(span_locations, not(fuzzing)))]
343338
pub fn invalidate_current_thread_spans() {
344-
SOURCE_MAP.with(|sm| {
345-
let mut sm = sm.borrow_mut();
346-
sm.files = vec![dummy_file()];
347-
});
339+
SOURCE_MAP.with(|sm| sm.borrow_mut().files.truncate(1));
348340
}
349341

350342
#[cfg(all(span_locations, not(fuzzing)))]

0 commit comments

Comments
 (0)