servo: Merge #10745 - Remove extra definition of WHITESPACE under components/util/str.rs (from zakorgy:refaktor); r=nox
authorzakorgyula <gyula.zakor@gmail.com>
Wed, 20 Apr 2016 13:55:23 +0500
changeset 338577 792eec72ff0c6d704e6830155693663cbf351fce
parent 338576 002c744d3f82eb4caea674b847e5476172cd52a8
child 338578 57e38431b42dbbb780283fbc03ff9dac00103597
push id31307
push usergszorc@mozilla.com
push dateSat, 04 Feb 2017 00:59:06 +0000
treeherdermozilla-central@94079d43835f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnox
servo: Merge #10745 - Remove extra definition of WHITESPACE under components/util/str.rs (from zakorgy:refaktor); r=nox issue: #10709 found another ``` const WHITESPACE: &'static [char] = &['\t', '\n', '\r', ' ']; ``` in ```components/style/viewports.rs ``` maybe this could be replaced too with the ```util::str::HTML_SPACE_CHARACTERS``` Source-Repo: https://github.com/servo/servo Source-Revision: ae63688db8cb7de8643845bdd5880cc50bf927f7
servo/components/script/dom/htmlfontelement.rs
servo/components/style/attr.rs
servo/components/util/str.rs
--- a/servo/components/script/dom/htmlfontelement.rs
+++ b/servo/components/script/dom/htmlfontelement.rs
@@ -10,17 +10,17 @@ use dom::bindings::inheritance::Castable
 use dom::bindings::js::{LayoutJS, Root};
 use dom::document::Document;
 use dom::element::{Element, RawLayoutElementHelpers};
 use dom::htmlelement::HTMLElement;
 use dom::node::Node;
 use dom::virtualmethods::VirtualMethods;
 use string_cache::Atom;
 use style::values::specified;
-use util::str::{DOMString, WHITESPACE, read_numbers};
+use util::str::{DOMString, HTML_SPACE_CHARACTERS, read_numbers};
 
 #[dom_struct]
 pub struct HTMLFontElement {
     htmlelement: HTMLElement,
 }
 
 
 impl HTMLFontElement {
@@ -119,17 +119,17 @@ impl HTMLFontElementLayoutHelpers for La
     }
 }
 
 /// https://html.spec.whatwg.org/multipage/#rules-for-parsing-a-legacy-font-size
 pub fn parse_legacy_font_size(mut input: &str) -> Option<&'static str> {
     // Steps 1 & 2 are not relevant
 
     // Step 3
-    input = input.trim_matches(WHITESPACE);
+    input = input.trim_matches(HTML_SPACE_CHARACTERS);
 
     enum ParseMode {
         RelativePlus,
         RelativeMinus,
         Absolute,
     }
     let mut input_chars = input.chars().peekable();
     let parse_mode = match input_chars.peek() {
--- a/servo/components/style/attr.rs
+++ b/servo/components/style/attr.rs
@@ -6,17 +6,17 @@ use app_units::Au;
 use cssparser::{self, Color, RGBA};
 use euclid::num::Zero;
 use num::ToPrimitive;
 use std::ascii::AsciiExt;
 use std::ops::Deref;
 use std::str::FromStr;
 use string_cache::{Atom, Namespace};
 use url::Url;
-use util::str::{DOMString, LengthOrPercentageOrAuto, HTML_SPACE_CHARACTERS, WHITESPACE};
+use util::str::{DOMString, LengthOrPercentageOrAuto, HTML_SPACE_CHARACTERS};
 use util::str::{read_numbers, split_html_space_chars, str_join};
 use values::specified::{Length};
 
 // Duplicated from script::dom::values.
 const UNSIGNED_LONG_MAX: u32 = 2147483647;
 
 #[derive(PartialEq, Clone, HeapSizeOf)]
 pub enum AttrValue {
@@ -274,17 +274,17 @@ pub fn parse_nonzero_length(value: &str)
 /// Parses a legacy color per HTML5 § 2.4.6. If unparseable, `Err` is returned.
 pub fn parse_legacy_color(mut input: &str) -> Result<RGBA, ()> {
     // Steps 1 and 2.
     if input.is_empty() {
         return Err(())
     }
 
     // Step 3.
-    input = input.trim_matches(WHITESPACE);
+    input = input.trim_matches(HTML_SPACE_CHARACTERS);
 
     // Step 4.
     if input.eq_ignore_ascii_case("transparent") {
         return Err(())
     }
 
     // Step 5.
     if let Ok(Color::RGBA(rgba)) = cssparser::parse_color_keyword(input) {
@@ -402,17 +402,17 @@ pub fn parse_legacy_color(mut input: &st
 /// TODO: this function can be rewritten to return Result<LengthOrPercentage, _>
 /// Parses a dimension value per HTML5 § 2.4.4.4. If unparseable, `Auto` is
 /// returned.
 /// https://html.spec.whatwg.org/multipage/#rules-for-parsing-dimension-values
 pub fn parse_length(mut value: &str) -> LengthOrPercentageOrAuto {
     // Steps 1 & 2 are not relevant
 
     // Step 3
-    value = value.trim_left_matches(WHITESPACE);
+    value = value.trim_left_matches(HTML_SPACE_CHARACTERS);
 
     // Step 4
     if value.is_empty() {
         return LengthOrPercentageOrAuto::Auto
     }
 
     // Step 5
     if value.starts_with("+") {
--- a/servo/components/util/str.rs
+++ b/servo/components/util/str.rs
@@ -119,40 +119,36 @@ impl Extend<char> for DOMString {
     fn extend<I>(&mut self, iterable: I) where I: IntoIterator<Item=char> {
         self.0.extend(iterable)
     }
 }
 
 pub type StaticCharVec = &'static [char];
 pub type StaticStringVec = &'static [&'static str];
 
-/// Whitespace as defined by HTML5 § 2.4.1.
-// TODO(SimonSapin) Maybe a custom Pattern can be more efficient?
-pub const WHITESPACE: &'static [char] = &[' ', '\t', '\x0a', '\x0c', '\x0d'];
-
-pub fn is_whitespace(s: &str) -> bool {
-    s.chars().all(char_is_whitespace)
-}
-
-#[inline]
-pub fn char_is_whitespace(c: char) -> bool {
-    WHITESPACE.contains(&c)
-}
-
 /// A "space character" according to:
 ///
 /// https://html.spec.whatwg.org/multipage/#space-character
 pub static HTML_SPACE_CHARACTERS: StaticCharVec = &[
     '\u{0020}',
     '\u{0009}',
     '\u{000a}',
     '\u{000c}',
     '\u{000d}',
 ];
 
+#[inline]
+pub fn char_is_whitespace(c: char) -> bool {
+    HTML_SPACE_CHARACTERS.contains(&c)
+}
+
+pub fn is_whitespace(s: &str) -> bool {
+    s.chars().all(char_is_whitespace)
+}
+
 pub fn split_html_space_chars<'a>(s: &'a str) ->
                                   Filter<Split<'a, StaticCharVec>, fn(&&str) -> bool> {
     fn not_empty(&split: &&str) -> bool { !split.is_empty() }
     s.split(HTML_SPACE_CHARACTERS).filter(not_empty as fn(&&str) -> bool)
 }
 
 
 fn is_ascii_digit(c: &char) -> bool {