aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/parse
diff options
context:
space:
mode:
authorSimon Sapin <simon.sapin@exyr.org>2015-06-25 20:40:38 -0700
committerSimon Sapin <simon.sapin@exyr.org>2015-06-25 20:40:38 -0700
commit34bfa1651793c3287e7c63f96d0095494af6eb29 (patch)
tree695fa05027c3883443760022d611bd377821ba19 /components/script/parse
parentea06bebca9fab485485ce60bd3f464bc64bf1c36 (diff)
downloadservo-34bfa1651793c3287e7c63f96d0095494af6eb29.tar.gz
servo-34bfa1651793c3287e7c63f96d0095494af6eb29.zip
Update to zero-copy* HTML parsing
html5ever now uses the Tendril string type to minimize copying internally, but Servo still converts from/to `String` at the boundary (which involves copying).
Diffstat (limited to 'components/script/parse')
-rw-r--r--components/script/parse/html.rs19
1 files changed, 11 insertions, 8 deletions
diff --git a/components/script/parse/html.rs b/components/script/parse/html.rs
index d7fd0946995..3401239382f 100644
--- a/components/script/parse/html.rs
+++ b/components/script/parse/html.rs
@@ -44,6 +44,7 @@ use html5ever::serialize::TraversalScope;
use html5ever::serialize::TraversalScope::{IncludeNode, ChildrenOnly};
use html5ever::tree_builder::{TreeSink, QuirksMode, NodeOrText, AppendNode, AppendText, NextParserState};
use string_cache::QualName;
+use tendril::StrTendril;
trait SinkHelpers {
fn get_or_create(&self, child: NodeOrText<JS<Node>>) -> Root<Node>;
@@ -55,7 +56,7 @@ impl SinkHelpers for servohtmlparser::Sink {
AppendNode(n) => n.root(),
AppendText(t) => {
let doc = self.document.root();
- let text = Text::new(t, doc.r());
+ let text = Text::new(t.into(), doc.r());
NodeCast::from_root(text)
}
}
@@ -91,16 +92,16 @@ impl<'a> TreeSink for servohtmlparser::Sink {
ElementCreator::ParserCreated);
for attr in attrs.into_iter() {
- elem.r().set_attribute_from_parser(attr.name, attr.value, None);
+ elem.r().set_attribute_from_parser(attr.name, attr.value.into(), None);
}
let node = NodeCast::from_ref(elem.r());
JS::from_ref(node)
}
- fn create_comment(&mut self, text: String) -> JS<Node> {
+ fn create_comment(&mut self, text: StrTendril) -> JS<Node> {
let doc = self.document.root();
- let comment = Comment::new(text, doc.r());
+ let comment = Comment::new(text.into(), doc.r());
let node = NodeCast::from_root(comment);
JS::from_rooted(&node)
}
@@ -137,10 +138,12 @@ impl<'a> TreeSink for servohtmlparser::Sink {
assert!(parent.r().AppendChild(child.r()).is_ok());
}
- fn append_doctype_to_document(&mut self, name: String, public_id: String, system_id: String) {
+ fn append_doctype_to_document(&mut self, name: StrTendril, public_id: StrTendril,
+ system_id: StrTendril) {
let doc = self.document.root();
let doc_node = NodeCast::from_ref(doc.r());
- let doctype = DocumentType::new(name, Some(public_id), Some(system_id), doc.r());
+ let doctype = DocumentType::new(
+ name.into(), Some(public_id.into()), Some(system_id.into()), doc.r());
let node: Root<Node> = NodeCast::from_root(doctype);
assert!(doc_node.AppendChild(node.r()).is_ok());
@@ -151,7 +154,7 @@ impl<'a> TreeSink for servohtmlparser::Sink {
let elem = ElementCast::to_ref(node.r())
.expect("tried to set attrs on non-Element in HTML parsing");
for attr in attrs.into_iter() {
- elem.set_attribute_from_parser(attr.name, attr.value, None);
+ elem.set_attribute_from_parser(attr.name, attr.value.into(), None);
}
}
@@ -275,7 +278,7 @@ pub fn parse_html(document: &Document,
ParseContext::Fragment(fc) =>
ServoHTMLParser::new_for_fragment(Some(url.clone()), document, fc),
};
- parser.r().parse_chunk(input);
+ parser.r().parse_chunk(input.into());
}
// https://html.spec.whatwg.org/multipage/#parsing-html-fragments