File tree Expand file tree Collapse file tree 1 file changed +7
-1
lines changed Expand file tree Collapse file tree 1 file changed +7
-1
lines changed Original file line number Diff line number Diff line change @@ -408,7 +408,13 @@ pub(super) fn write_code(
408
408
line_info : Option < LineInfo > ,
409
409
) {
410
410
// This replace allows to fix how the code source with DOS backline characters is displayed.
411
- let src = src. replace ( "\r \n " , "\n " ) ;
411
+ let src =
412
+ // The first "\r\n" should be fairly close to the beginning of the string relatively
413
+ // to its overall length, and most strings handled by rustdoc likely don't have
414
+ // DOS backlines anyway.
415
+ // Checking for the single ASCII character '\r' is much more efficient than checking for
416
+ // the whole string "\r\n".
417
+ if src. contains ( '\r' ) { src. replace ( "\r \n " , "\n " ) . into ( ) } else { Cow :: Borrowed ( src) } ;
412
418
let mut token_handler = TokenHandler {
413
419
out,
414
420
closing_tags : Vec :: new ( ) ,
You can’t perform that action at this time.
0 commit comments