File tree Expand file tree Collapse file tree 1 file changed +11
-3
lines changed Expand file tree Collapse file tree 1 file changed +11
-3
lines changed Original file line number Diff line number Diff line change @@ -163,8 +163,16 @@ impl ConcatSource {
163163
164164impl Source for ConcatSource {
165165 fn source ( & self ) -> SourceValue {
166- let rope = self . rope ( ) ;
167- SourceValue :: String ( Cow :: Owned ( rope. to_string ( ) ) )
166+ let children = self . optimized_children ( ) ;
167+ if children. len ( ) == 1 {
168+ children[ 0 ] . source ( )
169+ } else {
170+ let mut buf = String :: with_capacity ( self . size ( ) ) ;
171+ for child in children {
172+ buf. push_str ( & child. source ( ) . into_string_lossy ( ) ) ;
173+ }
174+ SourceValue :: String ( Cow :: Owned ( buf) )
175+ }
168176 }
169177
170178 fn rope ( & self ) -> Rope < ' _ > {
@@ -186,7 +194,7 @@ impl Source for ConcatSource {
186194 if children. len ( ) == 1 {
187195 children[ 0 ] . buffer ( )
188196 } else {
189- let mut buffer = vec ! [ ] ;
197+ let mut buffer = Vec :: with_capacity ( self . size ( ) ) ;
190198 self . to_writer ( & mut buffer) . unwrap ( ) ;
191199 Cow :: Owned ( buffer)
192200 }
You can’t perform that action at this time.
0 commit comments