mirror of
https://gitlab.com/xmpp-rs/xmpp-rs.git
synced 2024-07-12 22:21:53 +00:00
try not to allocate memory when comparing ending tags with starting tags
This commit is contained in:
parent
0e76e5211d
commit
cdb2cb8d86
1 changed files with 28 additions and 6 deletions
|
@ -340,12 +340,34 @@ impl Element {
|
||||||
}
|
}
|
||||||
let elem = stack.pop().unwrap();
|
let elem = stack.pop().unwrap();
|
||||||
if let Some(to) = stack.last_mut() {
|
if let Some(to) = stack.last_mut() {
|
||||||
let name = match elem.prefix() {
|
// TODO: check whether this is correct, we are comparing &[u8]s, not &strs
|
||||||
Some(ref prefix) => format!("{}:", prefix),
|
let elem_name = e.name();
|
||||||
None => String::from(""),
|
let mut split_iter = elem_name.splitn(2, |u| *u == 0x3A);
|
||||||
} + elem.name();
|
let possible_prefix = split_iter.next().unwrap(); // Can't be empty.
|
||||||
if name.as_bytes() != e.name() {
|
match split_iter.next() {
|
||||||
bail!(ErrorKind::InvalidElementClosed);
|
Some(name) => {
|
||||||
|
match elem.prefix() {
|
||||||
|
Some(prefix) => {
|
||||||
|
if possible_prefix != prefix.as_bytes() {
|
||||||
|
bail!(ErrorKind::InvalidElementClosed);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
None => {
|
||||||
|
bail!(ErrorKind::InvalidElementClosed);
|
||||||
|
},
|
||||||
|
}
|
||||||
|
if name != elem.name().as_bytes() {
|
||||||
|
bail!(ErrorKind::InvalidElementClosed);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
None => {
|
||||||
|
if elem.prefix().is_some() {
|
||||||
|
bail!(ErrorKind::InvalidElementClosed);
|
||||||
|
}
|
||||||
|
if possible_prefix != elem.name().as_bytes() {
|
||||||
|
bail!(ErrorKind::InvalidElementClosed);
|
||||||
|
}
|
||||||
|
},
|
||||||
}
|
}
|
||||||
to.append_child(elem);
|
to.append_child(elem);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue