Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/librustdoc/html/highlight.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,17 @@ fn write_code(
decoration_info: Option<DecorationInfo>,
) {
// This replace allows to fix how the code source with DOS backline characters is displayed.
let src = src.replace("\r\n", "\n");
let replaced;
// We don't typically expect to find carriage returns in the src text here,
// and at minimum replace(...) needs to allocate a new String and copy over,
// which can add up. This does mean we traverse src twice looking for
// carriage returns, but that's generally pretty fast.
let src = if src.contains("\r") {
replaced = src.replace("\r\n", "\n");
replaced.as_str()
} else {
src
};
Classifier::new(
&src,
edition,
Expand Down