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:
YouKnow 2024-08-27 05:53:37 +03:30
parent a77e9f58f0
commit 0c63375c03
2 changed files with 6 additions and 0 deletions

View file

@ -142,12 +142,14 @@ impl<'a> Render<'a> {
/// Render and return the text as **Html-formatted** string.
#[must_use]
#[inline]
pub fn as_html(&self) -> String {
self.format(&html::HTML)
}
/// Render and return the text as **Markdown-formatted** string.
#[must_use]
#[inline]
pub fn as_markdown(&self) -> String {
self.format(&markdown::MARKDOWN)
}

View file

@ -9,10 +9,12 @@ pub struct Tag<'a> {
}
impl<'a> Tag<'a> {
#[inline(always)]
pub const fn start(kind: Kind<'a>, offset: usize, index: usize) -> Self {
Self { place: Place::Start, kind, offset, index }
}
#[inline(always)]
pub const fn end(kind: Kind<'a>, offset: usize, index: usize) -> Self {
Self { place: Place::End, kind, offset, index }
}
@ -74,6 +76,7 @@ pub struct SimpleTag {
}
impl SimpleTag {
#[inline]
pub const fn new(start: &'static str, end: &'static str) -> Self {
Self { start, end }
}
@ -94,6 +97,7 @@ pub struct ComplexTag {
}
impl ComplexTag {
#[inline]
pub const fn new(start: &'static str, middle: &'static str, end: &'static str) -> Self {
Self { start, middle, end }
}