@@ -38,12 +38,13 @@ impl ChunkPart {
3838
3939 let mut all_range_content = String :: new ( ) ;
4040 for range in & self . ranges {
41- all_range_content += & content_between (
41+ append_content_between (
4242 range. line ,
4343 range. start_column ,
4444 range. line ,
4545 range. end_column ,
4646 lines,
47+ & mut all_range_content,
4748 ) ;
4849 }
4950 compressed_size_bytes ( all_range_content. into ( ) )
@@ -404,45 +405,48 @@ async fn unaccounted(
404405 } ] ) )
405406}
406407
407- fn content_between (
408+ fn append_content_between (
408409 start_line : u32 ,
409410 start_column : u32 ,
410411 end_line : u32 ,
411412 end_column : u32 ,
412413 lines : & [ FileLine ] ,
413- ) -> RcStr {
414+ out : & mut String ,
415+ ) {
414416 let start_line = start_line. min ( lines. len ( ) as u32 - 1 ) ;
415417 let end_line = end_line. min ( lines. len ( ) as u32 - 1 ) ;
416- if start_line == end_line {
417- let start_col = start_column. min ( lines[ start_line as usize ] . len ( ) as u32 ) ;
418- let end_col = end_column. min ( lines[ start_line as usize ] . len ( ) as u32 ) ;
419- if end_col < start_col {
420- return RcStr :: default ( ) ;
421- }
422- return lines[ start_line as usize ]
418+
419+ let start_column = start_column. min ( lines[ start_line as usize ] . len ( ) as u32 ) ;
420+ let end_column = if start_line == end_line {
421+ end_column. min ( lines[ start_line as usize ] . len ( ) as u32 )
422+ } else {
423+ lines[ start_line as usize ] . len ( ) as u32
424+ } ;
425+
426+ if end_column <= start_column {
427+ return ;
428+ }
429+
430+ out. extend (
431+ lines[ start_line as usize ]
423432 . content
424433 . chars ( )
425- . skip ( start_col as usize )
426- . take ( ( end_col - start_col) as usize )
427- . collect :: < String > ( )
428- . into ( ) ;
429- }
434+ . skip ( start_column as usize )
435+ . take ( ( end_column - start_column) as usize ) ,
436+ ) ;
430437
431- let mut out = String :: new ( ) ;
432- out += & lines[ start_line as usize ]
433- . content
434- . chars ( )
435- . skip ( start_column as usize )
436- . collect :: < String > ( ) ;
438+ if start_line == end_line {
439+ return ;
440+ }
437441
438442 for line in & lines[ start_line as usize + 1 ..end_line as usize ] {
439- out += & line. content ;
443+ out. push_str ( & line. content ) ;
440444 }
441445
442- out += & lines [ end_line as usize ]
443- . content
444- . chars ( )
445- . take ( end_column as usize )
446- . collect :: < String > ( ) ;
447- out . into ( )
446+ out. extend (
447+ lines [ end_line as usize ]
448+ . content
449+ . chars ( )
450+ . take ( end_column as usize ) ,
451+ ) ;
448452}
0 commit comments