mirror of
https://github.com/teloxide/teloxide.git
synced 2024-12-22 14:35:36 +01:00
perf(render): optimize tag and rendering functions with inline attributes
- Add #[inline] attribute to `as_html` and `as_markdown` methods in Render struct - Add #[inline(always)] attribute to `start` and `end` methods in Tag struct - Add #[inline] attribute to `new` methods in SimpleTag and ComplexTag structs
This commit is contained in:
parent
a77e9f58f0
commit
0c63375c03
2 changed files with 6 additions and 0 deletions
|
@ -142,12 +142,14 @@ impl<'a> Render<'a> {
|
||||||
|
|
||||||
/// Render and return the text as **Html-formatted** string.
|
/// Render and return the text as **Html-formatted** string.
|
||||||
#[must_use]
|
#[must_use]
|
||||||
|
#[inline]
|
||||||
pub fn as_html(&self) -> String {
|
pub fn as_html(&self) -> String {
|
||||||
self.format(&html::HTML)
|
self.format(&html::HTML)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Render and return the text as **Markdown-formatted** string.
|
/// Render and return the text as **Markdown-formatted** string.
|
||||||
#[must_use]
|
#[must_use]
|
||||||
|
#[inline]
|
||||||
pub fn as_markdown(&self) -> String {
|
pub fn as_markdown(&self) -> String {
|
||||||
self.format(&markdown::MARKDOWN)
|
self.format(&markdown::MARKDOWN)
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,10 +9,12 @@ pub struct Tag<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Tag<'a> {
|
impl<'a> Tag<'a> {
|
||||||
|
#[inline(always)]
|
||||||
pub const fn start(kind: Kind<'a>, offset: usize, index: usize) -> Self {
|
pub const fn start(kind: Kind<'a>, offset: usize, index: usize) -> Self {
|
||||||
Self { place: Place::Start, kind, offset, index }
|
Self { place: Place::Start, kind, offset, index }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
pub const fn end(kind: Kind<'a>, offset: usize, index: usize) -> Self {
|
pub const fn end(kind: Kind<'a>, offset: usize, index: usize) -> Self {
|
||||||
Self { place: Place::End, kind, offset, index }
|
Self { place: Place::End, kind, offset, index }
|
||||||
}
|
}
|
||||||
|
@ -74,6 +76,7 @@ pub struct SimpleTag {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SimpleTag {
|
impl SimpleTag {
|
||||||
|
#[inline]
|
||||||
pub const fn new(start: &'static str, end: &'static str) -> Self {
|
pub const fn new(start: &'static str, end: &'static str) -> Self {
|
||||||
Self { start, end }
|
Self { start, end }
|
||||||
}
|
}
|
||||||
|
@ -94,6 +97,7 @@ pub struct ComplexTag {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ComplexTag {
|
impl ComplexTag {
|
||||||
|
#[inline]
|
||||||
pub const fn new(start: &'static str, middle: &'static str, end: &'static str) -> Self {
|
pub const fn new(start: &'static str, middle: &'static str, end: &'static str) -> Self {
|
||||||
Self { start, middle, end }
|
Self { start, middle, end }
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue