From 0c63375c03e3d846ffaac2a4a56be1ffc21edd64 Mon Sep 17 00:00:00 2001 From: YouKnow Date: Tue, 27 Aug 2024 05:53:37 +0330 Subject: [PATCH] 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 --- crates/teloxide/src/utils/render/mod.rs | 2 ++ crates/teloxide/src/utils/render/tag.rs | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/crates/teloxide/src/utils/render/mod.rs b/crates/teloxide/src/utils/render/mod.rs index 2f42a89a..b8ffb8a1 100644 --- a/crates/teloxide/src/utils/render/mod.rs +++ b/crates/teloxide/src/utils/render/mod.rs @@ -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) } diff --git a/crates/teloxide/src/utils/render/tag.rs b/crates/teloxide/src/utils/render/tag.rs index 096b5d05..feff4d1c 100644 --- a/crates/teloxide/src/utils/render/tag.rs +++ b/crates/teloxide/src/utils/render/tag.rs @@ -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 } }