Skip to content
Merged
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
8 changes: 7 additions & 1 deletion src/librustdoc/html/highlight.rs
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,13 @@ pub(super) fn write_code(
line_info: Option<LineInfo>,
) {
// This replace allows to fix how the code source with DOS backline characters is displayed.
let src = src.replace("\r\n", "\n");
let src =
// The first "\r\n" should be fairly close to the beginning of the string relatively
// to its overall length, and most strings handled by rustdoc likely don't have
// DOS backlines anyway.
// Checking for the single ASCII character '\r' is much more efficient than checking for
// the whole string "\r\n".
if src.contains('\r') { src.replace("\r\n", "\n").into() } else { Cow::Borrowed(src) };
let mut token_handler = TokenHandler {
out,
closing_tags: Vec::new(),
Expand Down
Loading