File tree Expand file tree Collapse file tree 2 files changed +15
-1
lines changed Expand file tree Collapse file tree 2 files changed +15
-1
lines changed Original file line number Diff line number Diff line change @@ -94,7 +94,7 @@ impl<T> CachedSource<T> {
9494
9595impl < T : Source + Hash + PartialEq + Eq + ' static > Source for CachedSource < T > {
9696 fn source ( & self ) -> Cow < str > {
97- Cow :: Owned ( self . get_rope ( ) . to_string ( ) )
97+ self . get_rope ( ) . to_cow_string ( )
9898 }
9999
100100 fn rope ( & self ) -> Rope < ' _ > {
Original file line number Diff line number Diff line change @@ -461,6 +461,20 @@ impl<'a> Rope<'a> {
461461 }
462462 }
463463 }
464+
465+ /// Converts the rope to Cow<str>.
466+ pub fn to_cow_string ( & self ) -> Cow < str > {
467+ match & self . repr {
468+ Repr :: Light ( s) => Cow :: Borrowed ( s) ,
469+ Repr :: Full ( data) => {
470+ let mut s = String :: with_capacity ( self . len ( ) ) ;
471+ for ( chunk, _) in data. iter ( ) {
472+ s. push_str ( chunk) ;
473+ }
474+ Cow :: Owned ( s)
475+ }
476+ }
477+ }
464478}
465479
466480impl Hash for Rope < ' _ > {
You can’t perform that action at this time.
0 commit comments