@@ -438,17 +438,30 @@ impl<'a> From<Vec<Spans<'a>>> for Text<'a> {
439impl<'a> From<Text<'a>> for String {
439impl<'a> From<Text<'a>> for String {
440 fn from(text: Text<'a>) -> String {
440 fn from(text: Text<'a>) -> String {
441− let lines: Vec<String> = text.lines.iter().map(String::from).collect();
441+ String::from(&text)
446impl<'a> From<&Text<'a>> for String {
445impl<'a> From<&Text<'a>> for String {
447 fn from(text: &Text<'a>) -> String {
446 fn from(text: &Text<'a>) -> String {
448− let lines: Vec<String> = text.lines.iter().map(String::from).collect();
447+ let size = text
449− lines.join("\n")
448+ .lines
450+ .flat_map(|spans| spans.0.iter().map(|span| span.content.len()))
452+ + text.lines.len().saturating_sub(1); // for newline after each line
453+ let mut output = String::with_capacity(size);
455+ for spans in &text.lines {
456+ for span in &spans.0 {
457+ output.push_str(&span.content);
452impl<'a> IntoIterator for Text<'a> {
465impl<'a> IntoIterator for Text<'a> {
453 type Item = Spans<'a>;
466 type Item = Spans<'a>;
454 type IntoIter = std::vec::IntoIter<Self::Item>;
467 type IntoIter = std::vec::IntoIter<Self::Item>;