File tree 2 files changed +15
-1
lines changed
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> {
94
94
95
95
impl < T : Source + Hash + PartialEq + Eq + ' static > Source for CachedSource < T > {
96
96
fn source ( & self ) -> Cow < str > {
97
- Cow :: Owned ( self . get_rope ( ) . to_string ( ) )
97
+ self . get_rope ( ) . to_cow_string ( )
98
98
}
99
99
100
100
fn rope ( & self ) -> Rope < ' _ > {
Original file line number Diff line number Diff line change @@ -461,6 +461,20 @@ impl<'a> Rope<'a> {
461
461
}
462
462
}
463
463
}
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
+ }
464
478
}
465
479
466
480
impl Hash for Rope < ' _ > {
You can’t perform that action at this time.
0 commit comments