Skip to content

Commit e6f7be4

Browse files
Mingundralley
authored andcommitted
Add #[inline] to methods implementing XmlSource
Related: #678 All methods called only once or two and inlining them in most cases increases performance of our benchmarks: > critcmp master element-parser -t 5 group element-parser master ----- -------------- ------ NsReader::read_resolved_event_into/trim_text = false 1.00 398.9±6.30µs ? ?/sec 1.05 419.6±7.94µs ? ?/sec NsReader::read_resolved_event_into/trim_text = true 1.00 382.1±7.06µs ? ?/sec 1.06 404.0±7.44µs ? ?/sec One event/CData 1.00 56.3±0.97ns ? ?/sec 1.21 68.1±1.35ns ? ?/sec One event/Comment 1.00 141.2±2.52ns ? ?/sec 1.14 161.4±2.79ns ? ?/sec decode_and_parse_document_with_namespaces/rpm_filelists.xml 1.00 95.1±1.45µs 115.5 MB/sec 1.07 102.2±1.65µs 107.5 MB/sec escape_text/escaped_chars_long 1.42 1806.4±34.20ns ? ?/sec 1.00 1275.0±23.98ns ? ?/sec escape_text/escaped_chars_short 1.00 491.5±8.35ns ? ?/sec 1.07 526.6±10.80ns ? ?/sec escape_text/no_chars_to_escape_long 2.06 1831.1±36.31ns ? ?/sec 1.00 887.1±17.00ns ? ?/sec parse_document_nocopy_with_namespaces/libreoffice_document.fodt 1.00 507.2±8.56µs 107.6 MB/sec 1.08 546.2±10.20µs 100.0 MB/sec parse_document_nocopy_with_namespaces/rpm_filelists.xml 1.00 87.2±1.64µs 126.0 MB/sec 1.14 99.2±1.74µs 110.7 MB/sec parse_document_nocopy_with_namespaces/rpm_other.xml 1.00 139.6±2.83µs 158.5 MB/sec 1.07 148.7±2.71µs 148.9 MB/sec parse_document_nocopy_with_namespaces/rpm_primary.xml 1.00 190.5±3.43µs 106.4 MB/sec 1.09 207.9±3.79µs 97.5 MB/sec parse_document_nocopy_with_namespaces/rpm_primary2.xml 1.00 61.7±1.10µs 116.2 MB/sec 1.09 67.5±1.28µs 106.2 MB/sec parse_document_nocopy_with_namespaces/sample_1.xml 1.00 10.5±0.20µs 105.0 MB/sec 1.06 11.1±0.21µs 99.3 MB/sec parse_document_nocopy_with_namespaces/sample_ns.xml 1.00 8.4±0.16µs 86.5 MB/sec 1.08 9.0±0.18µs 80.0 MB/sec parse_document_nocopy_with_namespaces/sample_rss.xml 1.00 786.4±13.46µs 239.8 MB/sec 1.09 859.9±12.82µs 219.3 MB/sec parse_document_nocopy_with_namespaces/test_writer_ident.xml 1.00 29.0±0.55µs 146.4 MB/sec 1.06 30.8±0.55µs 138.0 MB/sec read_event/trim_text = false 1.00 199.3±3.59µs ? ?/sec 1.10 218.5±3.98µs ? ?/sec read_event/trim_text = true 1.00 190.4±3.76µs ? ?/sec 1.11 211.7±4.11µs ? ?/sec unescape_text/no_chars_to_unescape_short 1.00 11.8±0.21ns ? ?/sec 1.06 12.4±0.23ns ? ?/sec
1 parent 33b9dc5 commit e6f7be4

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

src/reader/buffered_reader.rs

+7
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use crate::reader::{is_whitespace, BangType, Parser, Reader, Span, XmlSource};
1313
macro_rules! impl_buffered_source {
1414
($($lf:lifetime, $reader:tt, $async:ident, $await:ident)?) => {
1515
#[cfg(not(feature = "encoding"))]
16+
#[inline]
1617
$($async)? fn remove_utf8_bom(&mut self) -> Result<()> {
1718
use crate::encoding::UTF8_BOM;
1819

@@ -31,6 +32,7 @@ macro_rules! impl_buffered_source {
3132
}
3233

3334
#[cfg(feature = "encoding")]
35+
#[inline]
3436
$($async)? fn detect_encoding(&mut self) -> Result<Option<&'static encoding_rs::Encoding>> {
3537
loop {
3638
break match self $(.$reader)? .fill_buf() $(.$await)? {
@@ -91,6 +93,7 @@ macro_rules! impl_buffered_source {
9193
Ok((&buf[start..], done))
9294
}
9395

96+
#[inline]
9497
$($async)? fn read_with<$($lf,)? P: Parser>(
9598
&mut self,
9699
mut parser: P,
@@ -133,6 +136,7 @@ macro_rules! impl_buffered_source {
133136
Err(Error::Syntax(P::eof_error()))
134137
}
135138

139+
#[inline]
136140
$($async)? fn read_bang_element $(<$lf>)? (
137141
&mut self,
138142
buf: &'b mut Vec<u8>,
@@ -183,6 +187,7 @@ macro_rules! impl_buffered_source {
183187
Err(bang_type.to_err())
184188
}
185189

190+
#[inline]
186191
$($async)? fn skip_whitespace(&mut self, position: &mut usize) -> Result<()> {
187192
loop {
188193
break match self $(.$reader)? .fill_buf() $(.$await)? {
@@ -202,6 +207,7 @@ macro_rules! impl_buffered_source {
202207
}
203208
}
204209

210+
#[inline]
205211
$($async)? fn skip_one(&mut self, byte: u8) -> Result<bool> {
206212
// search byte must be within the ascii range
207213
debug_assert!(byte.is_ascii());
@@ -215,6 +221,7 @@ macro_rules! impl_buffered_source {
215221
}
216222
}
217223

224+
#[inline]
218225
$($async)? fn peek_one(&mut self) -> Result<Option<u8>> {
219226
loop {
220227
break match self $(.$reader)? .fill_buf() $(.$await)? {

src/reader/slice_reader.rs

+8
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ impl<'a> Reader<&'a [u8]> {
237237
/// that will be borrowed by events. This implementation provides a zero-copy deserialization
238238
impl<'a> XmlSource<'a, ()> for &'a [u8] {
239239
#[cfg(not(feature = "encoding"))]
240+
#[inline]
240241
fn remove_utf8_bom(&mut self) -> Result<()> {
241242
if self.starts_with(crate::encoding::UTF8_BOM) {
242243
*self = &self[crate::encoding::UTF8_BOM.len()..];
@@ -245,6 +246,7 @@ impl<'a> XmlSource<'a, ()> for &'a [u8] {
245246
}
246247

247248
#[cfg(feature = "encoding")]
249+
#[inline]
248250
fn detect_encoding(&mut self) -> Result<Option<&'static Encoding>> {
249251
if let Some((enc, bom_len)) = crate::encoding::detect_encoding(self) {
250252
*self = &self[bom_len..];
@@ -253,6 +255,7 @@ impl<'a> XmlSource<'a, ()> for &'a [u8] {
253255
Ok(None)
254256
}
255257

258+
#[inline]
256259
fn read_bytes_until(
257260
&mut self,
258261
byte: u8,
@@ -275,6 +278,7 @@ impl<'a> XmlSource<'a, ()> for &'a [u8] {
275278
}
276279
}
277280

281+
#[inline]
278282
fn read_with<P>(&mut self, mut parser: P, _buf: (), position: &mut usize) -> Result<&'a [u8]>
279283
where
280284
P: Parser,
@@ -291,6 +295,7 @@ impl<'a> XmlSource<'a, ()> for &'a [u8] {
291295
Err(Error::Syntax(P::eof_error()))
292296
}
293297

298+
#[inline]
294299
fn read_bang_element(
295300
&mut self,
296301
_buf: (),
@@ -312,6 +317,7 @@ impl<'a> XmlSource<'a, ()> for &'a [u8] {
312317
Err(bang_type.to_err())
313318
}
314319

320+
#[inline]
315321
fn skip_whitespace(&mut self, position: &mut usize) -> Result<()> {
316322
let whitespaces = self
317323
.iter()
@@ -322,6 +328,7 @@ impl<'a> XmlSource<'a, ()> for &'a [u8] {
322328
Ok(())
323329
}
324330

331+
#[inline]
325332
fn skip_one(&mut self, byte: u8) -> Result<bool> {
326333
// search byte must be within the ascii range
327334
debug_assert!(byte.is_ascii());
@@ -333,6 +340,7 @@ impl<'a> XmlSource<'a, ()> for &'a [u8] {
333340
}
334341
}
335342

343+
#[inline]
336344
fn peek_one(&mut self) -> Result<Option<u8>> {
337345
Ok(self.first().copied())
338346
}

0 commit comments

Comments
 (0)