Join Atoms without requiring intermediate Vec

Related to: https://github.com/servo/string-cache/pull/89
This commit is contained in:
Corey Farwell 2015-07-04 18:41:47 -07:00
parent 0688488a7f
commit 9b2ba3d713

View file

@ -49,7 +49,11 @@ impl AttrValue {
}
pub fn from_atomic_tokens(atoms: Vec<Atom>) -> AttrValue {
let tokens = atoms.iter().map(|x| &**x).collect::<Vec<_>>().connect("\x20");
let tokens = atoms.iter().fold(String::new(), |mut s, atom| {
if !s.is_empty() { s.push('\x20'); }
s.push_str(atom);
s
});
AttrValue::TokenList(tokens, atoms)
}