aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbors-servo <release+servo@mozilla.com>2014-02-16 06:02:05 -0500
committerbors-servo <release+servo@mozilla.com>2014-02-16 06:02:05 -0500
commit41f55059a80156408368e375c2118066798958b9 (patch)
tree959f1849a8498ac11133c65dd3c1ddee2ed2e02c
parenta0b55b4c6cfacf3c9d59a07c8ee756c0dffad7f9 (diff)
parentf5561975671807492d81a11d0bab2567350309f0 (diff)
downloadservo-41f55059a80156408368e375c2118066798958b9.tar.gz
servo-41f55059a80156408368e375c2118066798958b9.zip
auto merge of #1703 : Ms2ger/servo/strings-cleanup, r=jdm
-rw-r--r--src/components/main/css/matching.rs5
-rw-r--r--src/components/main/layout/wrapper.rs8
-rw-r--r--src/components/script/dom/bindings/utils.rs10
-rw-r--r--src/components/script/dom/document.rs12
-rw-r--r--src/components/script/dom/documenttype.rs12
-rw-r--r--src/components/script/dom/element.rs7
-rw-r--r--src/components/script/dom/htmldocument.rs23
-rw-r--r--src/components/script/dom/node.rs2
-rw-r--r--src/components/script/html/hubbub_html_parser.rs3
-rw-r--r--src/components/script/script_task.rs8
-rw-r--r--src/components/style/selector_matching.rs40
11 files changed, 65 insertions, 65 deletions
diff --git a/src/components/main/css/matching.rs b/src/components/main/css/matching.rs
index 7b5961fd0bd..0f56c74fdfc 100644
--- a/src/components/main/css/matching.rs
+++ b/src/components/main/css/matching.rs
@@ -14,6 +14,7 @@ use script::layout_interface::LayoutChan;
use servo_util::cache::{Cache, LRUCache, SimpleHashCache};
use servo_util::namespace::Null;
use servo_util::smallvec::{SmallVec, SmallVec0, SmallVec16};
+use servo_util::str::DOMString;
use std::cast;
use std::to_bytes;
use std::vec::VecIterator;
@@ -161,9 +162,9 @@ struct StyleSharingCandidate {
priv parent_style: Arc<ComputedValues>,
// TODO(pcwalton): Intern.
- priv local_name: ~str,
+ priv local_name: DOMString,
- priv class: Option<~str>,
+ priv class: Option<DOMString>,
}
impl Eq for StyleSharingCandidate {
diff --git a/src/components/main/layout/wrapper.rs b/src/components/main/layout/wrapper.rs
index 8fc8bad2a33..2e67eff3567 100644
--- a/src/components/main/layout/wrapper.rs
+++ b/src/components/main/layout/wrapper.rs
@@ -241,13 +241,11 @@ impl<'ln> TNode<LayoutElement<'ln>> for LayoutNode<'ln> {
};
match attr.namespace {
SpecificNamespace(ref ns) => {
- match element.get_attr(ns, name) {
- Some(value) => test(value),
- None => false,
- }
+ element.get_attr(ns, name)
+ .map_default(false, |attr| test(attr))
},
// FIXME: https://github.com/mozilla/servo/issues/1558
- AnyNamespace => return false,
+ AnyNamespace => false,
}
})
}
diff --git a/src/components/script/dom/bindings/utils.rs b/src/components/script/dom/bindings/utils.rs
index 2c0d4943e6c..8cb42c86b4a 100644
--- a/src/components/script/dom/bindings/utils.rs
+++ b/src/components/script/dom/bindings/utils.rs
@@ -109,8 +109,8 @@ extern fn InterfaceObjectToString(cx: *JSContext, _argc: c_uint, vp: *mut JSVal)
let v = *GetFunctionNativeReserved(callee, TOSTRING_NAME_RESERVED_SLOT);
assert!(jsval::is_string(v));
let name = jsstring_to_str(cx, jsval::to_string(v));
- let retval = Some(~"function " + name + "() {\n [native code]\n}");
- *vp = domstring_to_jsval(cx, retval);
+ let retval = ~"function " + name + "() {\n [native code]\n}";
+ *vp = str_to_jsval(cx, retval);
return 1;
}
}
@@ -186,7 +186,7 @@ pub unsafe fn squirrel_away<T>(x: @mut T) -> *Box<T> {
y
}
-pub fn jsstring_to_str(cx: *JSContext, s: *JSString) -> ~str {
+pub fn jsstring_to_str(cx: *JSContext, s: *JSString) -> DOMString {
unsafe {
let length = 0;
let chars = JS_GetStringCharsAndLength(cx, s, &length);
@@ -196,7 +196,7 @@ pub fn jsstring_to_str(cx: *JSContext, s: *JSString) -> ~str {
}
}
-pub fn jsid_to_str(cx: *JSContext, id: jsid) -> ~str {
+pub fn jsid_to_str(cx: *JSContext, id: jsid) -> DOMString {
unsafe {
assert!(RUST_JSID_IS_STRING(id) != 0);
jsstring_to_str(cx, RUST_JSID_TO_STRING(id))
@@ -210,7 +210,7 @@ pub enum StringificationBehavior {
}
pub fn jsval_to_str(cx: *JSContext, v: JSVal,
- nullBehavior: StringificationBehavior) -> Result<~str, ()> {
+ nullBehavior: StringificationBehavior) -> Result<DOMString, ()> {
if jsval::is_null(v) && nullBehavior == Empty {
Ok(~"")
} else {
diff --git a/src/components/script/dom/document.rs b/src/components/script/dom/document.rs
index 4807eaa02ad..37df96353a9 100644
--- a/src/components/script/dom/document.rs
+++ b/src/components/script/dom/document.rs
@@ -32,7 +32,6 @@ use js::jsapi::{JSObject, JSContext, JSTracer};
use std::ascii::StrAsciiExt;
use std::cast;
use std::hashmap::HashMap;
-use std::str::eq_slice;
use std::unstable::raw::Box;
#[deriving(Eq)]
@@ -247,7 +246,7 @@ impl Document {
// http://dom.spec.whatwg.org/#dom-document-getelementsbytagname
pub fn GetElementsByTagName(&self, tag: DOMString) -> @mut HTMLCollection {
- self.createHTMLCollection(|elem| eq_slice(elem.tag_name, tag))
+ self.createHTMLCollection(|elem| elem.tag_name == tag)
}
// http://dom.spec.whatwg.org/#dom-document-getelementsbytagnamens
@@ -342,7 +341,7 @@ impl Document {
for child in node.children() {
if child.is_text() {
child.with_imm_text(|text| {
- title = title + text.characterdata.Data();
+ title.push_str(text.characterdata.data.as_slice());
});
}
}
@@ -467,8 +466,11 @@ impl Document {
// http://www.whatwg.org/specs/web-apps/current-work/#dom-document-getelementsbyname
pub fn GetElementsByName(&self, name: DOMString) -> @mut HTMLCollection {
- self.createHTMLCollection(|elem|
- elem.get_attribute(Null, "name").is_some() && eq_slice(elem.get_attribute(Null, "name").unwrap().value_ref(), name))
+ self.createHTMLCollection(|elem| {
+ elem.get_attribute(Null, "name").map_default(false, |attr| {
+ attr.value_ref() == name
+ })
+ })
}
pub fn createHTMLCollection(&self, callback: |elem: &Element| -> bool) -> @mut HTMLCollection {
diff --git a/src/components/script/dom/documenttype.rs b/src/components/script/dom/documenttype.rs
index ee2e18ea969..f161b287702 100644
--- a/src/components/script/dom/documenttype.rs
+++ b/src/components/script/dom/documenttype.rs
@@ -16,9 +16,9 @@ pub struct DocumentType {
}
impl DocumentType {
- pub fn new_inherited(name: ~str,
- public_id: Option<~str>,
- system_id: Option<~str>,
+ pub fn new_inherited(name: DOMString,
+ public_id: Option<DOMString>,
+ system_id: Option<DOMString>,
document: AbstractDocument)
-> DocumentType {
DocumentType {
@@ -29,9 +29,9 @@ impl DocumentType {
}
}
- pub fn new(name: ~str,
- public_id: Option<~str>,
- system_id: Option<~str>,
+ pub fn new(name: DOMString,
+ public_id: Option<DOMString>,
+ system_id: Option<DOMString>,
document: AbstractDocument)
-> AbstractNode {
let documenttype = DocumentType::new_inherited(name,
diff --git a/src/components/script/dom/element.rs b/src/components/script/dom/element.rs
index 1404a4f0347..8efd60b8d4c 100644
--- a/src/components/script/dom/element.rs
+++ b/src/components/script/dom/element.rs
@@ -26,12 +26,11 @@ use servo_util::str::{DOMString, null_str_as_empty_ref};
use std::ascii::StrAsciiExt;
use std::cast;
-use std::str::eq;
use std::unstable::raw::Box;
pub struct Element {
node: Node,
- tag_name: ~str, // TODO: This should be an atom, not a ~str.
+ tag_name: DOMString, // TODO: This should be an atom, not a DOMString.
namespace: Namespace,
attrs: ~[@mut Attr],
style_attribute: Option<style::PropertyDeclarationBlock>,
@@ -181,8 +180,8 @@ impl Element {
match prefix {
Some(ref prefix_str) => {
if (namespace == namespace::Null ||
- (eq(prefix_str, &~"xml") && namespace != namespace::XML) ||
- (eq(prefix_str, &~"xmlns") && namespace != namespace::XMLNS)) {
+ ("xml" == prefix_str.as_slice() && namespace != namespace::XML) ||
+ ("xmlns" == prefix_str.as_slice() && namespace != namespace::XMLNS)) {
return Err(NamespaceError);
}
},
diff --git a/src/components/script/dom/htmldocument.rs b/src/components/script/dom/htmldocument.rs
index 6dcab51fa89..8297fd3e90c 100644
--- a/src/components/script/dom/htmldocument.rs
+++ b/src/components/script/dom/htmldocument.rs
@@ -11,7 +11,6 @@ use servo_util::namespace::Null;
use extra::url::Url;
use js::jsapi::JSTracer;
-use std::str::eq_slice;
pub struct HTMLDocument {
parent: Document
@@ -32,11 +31,11 @@ impl HTMLDocument {
impl HTMLDocument {
pub fn Images(&self) -> @mut HTMLCollection {
- self.parent.createHTMLCollection(|elem| eq_slice(elem.tag_name, "img"))
+ self.parent.createHTMLCollection(|elem| "img" == elem.tag_name)
}
pub fn Embeds(&self) -> @mut HTMLCollection {
- self.parent.createHTMLCollection(|elem| eq_slice(elem.tag_name, "embed"))
+ self.parent.createHTMLCollection(|elem| "embed" == elem.tag_name)
}
pub fn Plugins(&self) -> @mut HTMLCollection {
@@ -44,27 +43,29 @@ impl HTMLDocument {
}
pub fn Links(&self) -> @mut HTMLCollection {
- self.parent.createHTMLCollection(|elem|
- (eq_slice(elem.tag_name, "a") || eq_slice(elem.tag_name, "area"))
- && elem.get_attribute(Null, "href").is_some())
+ self.parent.createHTMLCollection(|elem| {
+ ("a" == elem.tag_name || "area" == elem.tag_name) &&
+ elem.get_attribute(Null, "href").is_some()
+ })
}
pub fn Forms(&self) -> @mut HTMLCollection {
- self.parent.createHTMLCollection(|elem| eq_slice(elem.tag_name, "form"))
+ self.parent.createHTMLCollection(|elem| "form" == elem.tag_name)
}
pub fn Scripts(&self) -> @mut HTMLCollection {
- self.parent.createHTMLCollection(|elem| eq_slice(elem.tag_name, "script"))
+ self.parent.createHTMLCollection(|elem| "script" == elem.tag_name)
}
pub fn Anchors(&self) -> @mut HTMLCollection {
- self.parent.createHTMLCollection(|elem|
- eq_slice(elem.tag_name, "a") && elem.get_attribute(Null, "name").is_some())
+ self.parent.createHTMLCollection(|elem| {
+ "a" == elem.tag_name && elem.get_attribute(Null, "name").is_some()
+ })
}
pub fn Applets(&self) -> @mut HTMLCollection {
// FIXME: This should be return OBJECT elements containing applets.
- self.parent.createHTMLCollection(|elem| eq_slice(elem.tag_name, "applet"))
+ self.parent.createHTMLCollection(|elem| "applet" == elem.tag_name)
}
}
diff --git a/src/components/script/dom/node.rs b/src/components/script/dom/node.rs
index adf248ef07f..8150de40919 100644
--- a/src/components/script/dom/node.rs
+++ b/src/components/script/dom/node.rs
@@ -1064,7 +1064,7 @@ impl Node {
for node in abstract_self.traverse_preorder() {
if node.is_text() {
node.with_imm_text(|text| {
- content = content + text.characterdata.Data();
+ content.push_str(text.characterdata.data.as_slice());
})
}
}
diff --git a/src/components/script/html/hubbub_html_parser.rs b/src/components/script/html/hubbub_html_parser.rs
index ac50e9cfc34..1079e5986ef 100644
--- a/src/components/script/html/hubbub_html_parser.rs
+++ b/src/components/script/html/hubbub_html_parser.rs
@@ -27,7 +27,6 @@ use std::cast;
use std::cell::RefCell;
use std::comm::{Port, SharedChan};
use std::from_str::FromStr;
-use std::str::eq_slice;
use std::str;
use style::Stylesheet;
@@ -37,7 +36,7 @@ macro_rules! handle_element(
$string: expr,
$ctor: ident
$(, $arg:expr )*) => (
- if eq_slice($localName, $string) {
+ if $string == $localName {
return $ctor::new($localName, $document $(, $arg)*);
}
)
diff --git a/src/components/script/script_task.rs b/src/components/script/script_task.rs
index b835798e874..8a56291b95f 100644
--- a/src/components/script/script_task.rs
+++ b/src/components/script/script_task.rs
@@ -49,7 +49,6 @@ use servo_util::task::send_on_failure;
use servo_util::namespace::Null;
use std::comm::{Port, SharedChan};
use std::ptr;
-use std::str::eq_slice;
use std::task;
use std::util::replace;
@@ -796,10 +795,9 @@ impl ScriptTask {
let mut anchors = doc_node.traverse_preorder().filter(|node| node.is_anchor_element());
anchors.find(|node| {
node.with_imm_element(|elem| {
- match elem.get_attribute(Null, "name") {
- Some(name) => eq_slice(name.value_ref(), fragid),
- None => false
- }
+ elem.get_attribute(Null, "name").map_default(false, |attr| {
+ attr.value_ref() == fragid
+ })
})
})
}
diff --git a/src/components/style/selector_matching.rs b/src/components/style/selector_matching.rs
index 4d646964c37..4b1b884e6e3 100644
--- a/src/components/style/selector_matching.rs
+++ b/src/components/style/selector_matching.rs
@@ -5,12 +5,12 @@
use extra::arc::Arc;
use std::ascii::StrAsciiExt;
use std::hashmap::HashMap;
-use std::str;
use std::to_bytes;
use servo_util::namespace;
use servo_util::smallvec::SmallVec;
use servo_util::sort;
+use servo_util::str::DOMString;
use media_queries::{Device, Screen};
use node::{TElement, TNode};
@@ -31,8 +31,8 @@ static SELECTOR_WHITESPACE: &'static [char] = &'static [' ', '\t', '\n', '\r', '
/// string.
struct LowercaseAsciiString<'a>(&'a str);
-impl<'a> Equiv<~str> for LowercaseAsciiString<'a> {
- fn equiv(&self, other: &~str) -> bool {
+impl<'a> Equiv<DOMString> for LowercaseAsciiString<'a> {
+ fn equiv(&self, other: &DOMString) -> bool {
let LowercaseAsciiString(this) = *self;
this.eq_ignore_ascii_case(*other)
}
@@ -79,9 +79,9 @@ impl<'a> IterBytes for LowercaseAsciiString<'a> {
struct SelectorMap {
// TODO: Tune the initial capacity of the HashMap
// FIXME: Use interned strings
- id_hash: HashMap<~str, ~[Rule]>,
- class_hash: HashMap<~str, ~[Rule]>,
- element_hash: HashMap<~str, ~[Rule]>,
+ id_hash: HashMap<DOMString, ~[Rule]>,
+ class_hash: HashMap<DOMString, ~[Rule]>,
+ element_hash: HashMap<DOMString, ~[Rule]>,
// For Rules that don't have ID, class, or element selectors.
universal_rules: ~[Rule],
/// Whether this hash is empty.
@@ -163,7 +163,7 @@ impl SelectorMap {
N:TNode<E>,
V:SmallVec<MatchedProperty>>(
node: &N,
- hash: &HashMap<~str,~[Rule]>,
+ hash: &HashMap<DOMString,~[Rule]>,
key: &str,
matching_rules: &mut V,
shareable: &mut bool) {
@@ -179,7 +179,7 @@ impl SelectorMap {
N:TNode<E>,
V:SmallVec<MatchedProperty>>(
node: &N,
- hash: &HashMap<~str,~[Rule]>,
+ hash: &HashMap<DOMString,~[Rule]>,
key: &str,
matching_rules: &mut V,
shareable: &mut bool) {
@@ -595,21 +595,20 @@ fn matches_simple_selector<E:TElement,
IDSelector(ref id) => {
*shareable = false;
element.with_element(|element: &E| {
- match element.get_attr(&namespace::Null, "id") {
- Some(attr) => str::eq_slice(attr, *id),
- None => false
- }
+ element.get_attr(&namespace::Null, "id")
+ .map_default(false, |attr| {
+ attr == *id
+ })
})
}
// TODO: cache and intern class names on elements.
ClassSelector(ref class) => {
element.with_element(|element: &E| {
- match element.get_attr(&namespace::Null, "class") {
- None => false,
+ element.get_attr(&namespace::Null, "class")
+ .map_default(false, |attr| {
// TODO: case-sensitivity depends on the document type and quirks mode
- Some(ref class_attr)
- => class_attr.split(SELECTOR_WHITESPACE).any(|c| c == class.as_slice()),
- }
+ attr.split(SELECTOR_WHITESPACE).any(|c| c == class.as_slice())
+ })
})
}
@@ -623,7 +622,9 @@ fn matches_simple_selector<E:TElement,
// here because the UA style otherwise disables all style sharing completely.
*shareable = false
}
- element.match_attr(attr, |v| v == value.as_slice())
+ element.match_attr(attr, |attr_value| {
+ attr_value == value.as_slice()
+ })
}
AttrIncludes(ref attr, ref value) => {
*shareable = false;
@@ -634,7 +635,8 @@ fn matches_simple_selector<E:TElement,
AttrDashMatch(ref attr, ref value, ref dashing_value) => {
*shareable = false;
element.match_attr(attr, |attr_value| {
- attr_value == value.as_slice() || attr_value.starts_with(dashing_value.as_slice())
+ attr_value == value.as_slice() ||
+ attr_value.starts_with(dashing_value.as_slice())
})
}
AttrPrefixMatch(ref attr, ref value) => {