mirror of
https://github.com/servo/servo.git
synced 2025-08-05 21:50:18 +01:00
Change Namespace::to_str() to not allocate and return a reference.
This commit is contained in:
parent
28575c20bf
commit
61c7f2f220
5 changed files with 23 additions and 23 deletions
|
@ -75,7 +75,7 @@ impl Attr {
|
|||
}
|
||||
|
||||
pub fn GetNamespaceURI(&self) -> Option<DOMString> {
|
||||
self.namespace.to_str()
|
||||
self.namespace.to_str().map(|s| s.to_owned())
|
||||
}
|
||||
|
||||
pub fn GetPrefix(&self) -> Option<DOMString> {
|
||||
|
|
|
@ -129,8 +129,8 @@ impl ElementLike for Element {
|
|||
self.tag_name.as_slice()
|
||||
}
|
||||
|
||||
fn get_namespace<'a>(&'a self) -> ~str {
|
||||
self.namespace.to_str().unwrap_or(~"")
|
||||
fn get_namespace_url<'a>(&'a self) -> &'a str {
|
||||
self.namespace.to_str().unwrap_or("")
|
||||
}
|
||||
|
||||
fn get_attr(&self, name: &str) -> Option<~str> {
|
||||
|
|
|
@ -19,26 +19,26 @@ pub enum Namespace {
|
|||
impl Namespace {
|
||||
pub fn from_str(url: Option<DOMString>) -> Namespace {
|
||||
match null_str_as_empty_ref(&url) {
|
||||
&"http://www.w3.org/1999/xhtml" => HTML,
|
||||
&"http://www.w3.org/XML/1998/namespace" => XML,
|
||||
&"http://www.w3.org/2000/xmlns/" => XMLNS,
|
||||
&"http://www.w3.org/1999/xlink" => XLink,
|
||||
&"http://www.w3.org/2000/svg" => SVG,
|
||||
&"http://www.w3.org/1998/Math/MathML" => MathML,
|
||||
&"" => Null,
|
||||
"http://www.w3.org/1999/xhtml" => HTML,
|
||||
"http://www.w3.org/XML/1998/namespace" => XML,
|
||||
"http://www.w3.org/2000/xmlns/" => XMLNS,
|
||||
"http://www.w3.org/1999/xlink" => XLink,
|
||||
"http://www.w3.org/2000/svg" => SVG,
|
||||
"http://www.w3.org/1998/Math/MathML" => MathML,
|
||||
"" => Null,
|
||||
ns => Other(ns.to_owned())
|
||||
}
|
||||
}
|
||||
pub fn to_str(&self) -> Option<DOMString> {
|
||||
pub fn to_str<'a>(&'a self) -> Option<&'a str> {
|
||||
match *self {
|
||||
Null => None,
|
||||
HTML => Some(~"http://www.w3.org/1999/xhtml"),
|
||||
XML => Some(~"http://www.w3.org/XML/1998/namespace"),
|
||||
XMLNS => Some(~"http://www.w3.org/2000/xmlns/"),
|
||||
XLink => Some(~"http://www.w3.org/1999/xlink"),
|
||||
SVG => Some(~"http://www.w3.org/2000/svg"),
|
||||
MathML => Some(~"http://www.w3.org/1998/Math/MathML"),
|
||||
Other(ref x) => Some(x.to_owned())
|
||||
HTML => Some("http://www.w3.org/1999/xhtml"),
|
||||
XML => Some("http://www.w3.org/XML/1998/namespace"),
|
||||
XMLNS => Some("http://www.w3.org/2000/xmlns/"),
|
||||
XLink => Some("http://www.w3.org/1999/xlink"),
|
||||
SVG => Some("http://www.w3.org/2000/svg"),
|
||||
MathML => Some("http://www.w3.org/1998/Math/MathML"),
|
||||
Other(ref x) => Some(x.as_slice())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue