Skip to content

Commit 59ccbc2

Browse files
committed
Do not repeat subslicing the buf
1 parent 5aa1004 commit 59ccbc2

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/reader/state.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -132,17 +132,18 @@ impl ReaderState {
132132
/// Wraps content of `buf` into the [`Event::End`] event. Does the check that
133133
/// end name matches the last opened start name if `self.check_end_names` is set.
134134
pub fn emit_end<'b>(&mut self, buf: &'b [u8]) -> Result<Event<'b>> {
135+
// Strip the `/` character. `content` contains data between `</` and `>`
136+
let content = &buf[1..];
135137
// XML standard permits whitespaces after the markup name in closing tags.
136138
// Let's strip them from the buffer before comparing tag names.
137139
let name = if self.trim_markup_names_in_closing_tags {
138-
if let Some(pos_end_name) = buf[1..].iter().rposition(|&b| !is_whitespace(b)) {
139-
let (name, _) = buf[1..].split_at(pos_end_name + 1);
140-
name
140+
if let Some(pos_end_name) = content.iter().rposition(|&b| !is_whitespace(b)) {
141+
&content[..pos_end_name + 1]
141142
} else {
142-
&buf[1..]
143+
content
143144
}
144145
} else {
145-
&buf[1..]
146+
content
146147
};
147148

148149
let decoder = self.decoder();

0 commit comments

Comments
 (0)