From 26f03c27edbe798f0a77f34d4c352f4e4fd79afe Mon Sep 17 00:00:00 2001 From: Astro Date: Sat, 12 Aug 2017 02:13:32 +0200 Subject: [PATCH] optimize Element::write_to_inner() with CoW --- src/element.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/element.rs b/src/element.rs index 5aecfa8..2c16b3c 100644 --- a/src/element.rs +++ b/src/element.rs @@ -6,6 +6,7 @@ use std::collections::{btree_map, BTreeMap}; use std::str; use std::cell::RefCell; use std::rc::Rc; +use std::borrow::Cow; use error::{Error, ErrorKind, Result}; @@ -431,8 +432,8 @@ impl Element { /// Like `write_to()` but without the `` prelude pub fn write_to_inner(&self, writer: &mut W) -> Result<()> { let name = match &self.prefix { - &None => self.name.to_owned(), - &Some(ref prefix) => format!("{}:{}", prefix, self.name), + &None => Cow::Borrowed(&self.name), + &Some(ref prefix) => Cow::Owned(format!("{}:{}", prefix, self.name)), }; write!(writer, "<{}", name)?;