File tree Expand file tree Collapse file tree 1 file changed +11
-1
lines changed
Expand file tree Collapse file tree 1 file changed +11
-1
lines changed Original file line number Diff line number Diff line change @@ -98,7 +98,17 @@ fn write_code(
9898 decoration_info : Option < DecorationInfo > ,
9999) {
100100 // This replace allows to fix how the code source with DOS backline characters is displayed.
101- let src = src. replace ( "\r \n " , "\n " ) ;
101+ let replaced;
102+ // We don't typically expect to find carriage returns in the src text here,
103+ // and at minimum replace(...) needs to allocate a new String and copy over,
104+ // which can add up. This does mean we traverse src twice looking for
105+ // carriage returns, but that's generally pretty fast.
106+ let src = if src. contains ( "\r " ) {
107+ replaced = src. replace ( "\r \n " , "\n " ) ;
108+ replaced. as_str ( )
109+ } else {
110+ src
111+ } ;
102112 Classifier :: new (
103113 & src,
104114 edition,
You can’t perform that action at this time.
0 commit comments