Skip to content

Commit a137c23

Browse files
committed
Don't copy file contents just to remove the BOM
1 parent 3b71d3a commit a137c23

File tree

4 files changed

+7
-8
lines changed

4 files changed

+7
-8
lines changed

src/librustdoc/html/highlight.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use rustc_span::with_default_session_globals;
1717

1818
/// Highlights `src`, returning the HTML output.
1919
crate fn render_with_highlighting(
20-
src: String,
20+
src: &str,
2121
class: Option<&str>,
2222
playground_button: Option<&str>,
2323
tooltip: Option<(Option<Edition>, &str)>,

src/librustdoc/html/markdown.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ impl<'a, I: Iterator<Item = Event<'a>>> Iterator for CodeBlocks<'_, 'a, I> {
299299
};
300300

301301
s.push_str(&highlight::render_with_highlighting(
302-
text,
302+
&text,
303303
Some(&format!(
304304
"rust-example-rendered{}",
305305
if let Some((_, class)) = tooltip { format!(" {}", class) } else { String::new() }

src/librustdoc/html/render/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4785,7 +4785,7 @@ fn sidebar_foreign_type(cx: &Context<'_>, buf: &mut Buffer, it: &clean::Item) {
47854785
fn item_macro(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clean::Macro) {
47864786
wrap_into_docblock(w, |w| {
47874787
w.write_str(&highlight::render_with_highlighting(
4788-
t.source.clone(),
4788+
&t.source,
47894789
Some("macro"),
47904790
None,
47914791
None,

src/librustdoc/html/sources.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,17 +86,16 @@ impl SourceCollector<'_, '_> {
8686
return Ok(());
8787
}
8888

89-
let mut contents = match fs::read_to_string(&p) {
89+
let contents = match fs::read_to_string(&p) {
9090
Ok(contents) => contents,
9191
Err(e) => {
9292
return Err(Error::new(e, &p));
9393
}
9494
};
9595

9696
// Remove the utf-8 BOM if any
97-
if contents.starts_with('\u{feff}') {
98-
contents.drain(..3);
99-
}
97+
let contents =
98+
if contents.starts_with('\u{feff}') { &contents[3..] } else { &contents[..] };
10099

101100
// Create the intermediate directories
102101
let mut cur = self.dst.clone();
@@ -171,7 +170,7 @@ where
171170

172171
/// Wrapper struct to render the source code of a file. This will do things like
173172
/// adding line numbers to the left-hand side.
174-
fn print_src(buf: &mut Buffer, s: String, edition: Edition) {
173+
fn print_src(buf: &mut Buffer, s: &str, edition: Edition) {
175174
let lines = s.lines().count();
176175
let mut cols = 0;
177176
let mut tmp = lines;

0 commit comments

Comments
 (0)