From f14f09e8868d0cad0308c2fa8eec8369560ee096 Mon Sep 17 00:00:00 2001 From: Corey Farwell Date: Mon, 28 Sep 2015 19:57:06 -0400 Subject: [PATCH] Use util::str::str_join in more places Instead of intermediate allocations of `Vec`s, we should utilize `str_join` which operates on iterators --- components/script/dom/cssstyledeclaration.rs | 7 +++---- components/script/dom/document.rs | 4 ++-- components/script/dom/htmloptionelement.rs | 5 ++--- components/script/lib.rs | 1 - 4 files changed, 7 insertions(+), 10 deletions(-) diff --git a/components/script/dom/cssstyledeclaration.rs b/components/script/dom/cssstyledeclaration.rs index e2bf6fd771b..68dd897eb84 100644 --- a/components/script/dom/cssstyledeclaration.rs +++ b/components/script/dom/cssstyledeclaration.rs @@ -15,11 +15,10 @@ use selectors::parser::PseudoElement; use std::ascii::AsciiExt; use std::borrow::ToOwned; use std::cell::Ref; -use std::slice::SliceConcatExt; use string_cache::Atom; use style::properties::PropertyDeclaration; use style::properties::{is_supported_property, longhands_from_shorthand, parse_one_declaration}; -use util::str::DOMString; +use util::str::{DOMString, str_join}; // http://dev.w3.org/csswg/cssom/#the-cssstyledeclaration-interface #[dom_struct] @@ -50,8 +49,8 @@ macro_rules! css_properties( ); fn serialize_list(list: &[Ref]) -> DOMString { - let strings: Vec<_> = list.iter().map(|d| d.value()).collect(); - strings.join(" ") + let str_iter = list.iter().map(|d| d.value()); + str_join(str_iter, " ") } impl CSSStyleDeclaration { diff --git a/components/script/dom/document.rs b/components/script/dom/document.rs index db4c72af8dc..c68924c3fd6 100644 --- a/components/script/dom/document.rs +++ b/components/script/dom/document.rs @@ -98,7 +98,7 @@ use std::sync::mpsc::channel; use string_cache::{Atom, QualName}; use time; use url::Url; -use util::str::{DOMString, split_html_space_chars}; +use util::str::{DOMString, split_html_space_chars, str_join}; #[derive(JSTraceable, PartialEq, HeapSizeOf)] pub enum IsHTMLDocument { @@ -1443,7 +1443,7 @@ impl DocumentMethods for Document { Some(ref title) => { // Steps 3-4. let value = Node::collect_text_contents(title.r().children()); - split_html_space_chars(&value).collect::>().join(" ") + str_join(split_html_space_chars(&value), " ") }, } } diff --git a/components/script/dom/htmloptionelement.rs b/components/script/dom/htmloptionelement.rs index 79f710db1d2..432d6dc2bee 100644 --- a/components/script/dom/htmloptionelement.rs +++ b/components/script/dom/htmloptionelement.rs @@ -18,7 +18,7 @@ use dom::htmlelement::{HTMLElement, HTMLElementTypeId}; use dom::node::{Node, NodeTypeId}; use dom::virtualmethods::VirtualMethods; use std::cell::Cell; -use util::str::{DOMString, split_html_space_chars}; +use util::str::{DOMString, split_html_space_chars, str_join}; #[dom_struct] pub struct HTMLOptionElement { @@ -93,8 +93,7 @@ impl HTMLOptionElementMethods for HTMLOptionElement { let node = NodeCast::from_ref(self); let mut content = String::new(); collect_text(&node, &mut content); - let v: Vec<&str> = split_html_space_chars(&content).collect(); - v.join(" ") + str_join(split_html_space_chars(&content), " ") } // https://www.whatwg.org/html/#dom-option-text diff --git a/components/script/lib.rs b/components/script/lib.rs index 40df1c66ed2..6ebf3d12df6 100644 --- a/components/script/lib.rs +++ b/components/script/lib.rs @@ -24,7 +24,6 @@ #![feature(str_utf16)] #![feature(unicode)] #![feature(vec_push_all)] -#![feature(slice_concat_ext)] #![deny(unsafe_code)] #![allow(non_snake_case)]