perf: `IntoView` and `IntoAttribute` for `std::fmt::Arguments` improvements (#1947)

* fix: use static str when possible in `std::fmt::Arguments` in views

* feat: impl `IntoAttribute` for `std::fmt::Arguments`
This commit is contained in:
Ari Seyhun 2023-10-28 04:12:27 +10:30 committed by GitHub
parent 6361985fb1
commit a2bef05a4b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 1 deletions

View File

@ -1173,6 +1173,19 @@ where
}
}
impl IntoView for std::fmt::Arguments<'_> {
#[cfg_attr(
any(debug_assertions, feature = "ssr"),
instrument(level = "info", name = "#text", skip_all)
)]
fn into_view(self) -> View {
match self.as_str() {
Some(s) => s.into_view(),
None => self.to_string().into_view(),
}
}
}
macro_rules! viewable_primitive {
($($child_type:ty),* $(,)?) => {
$(
@ -1226,7 +1239,6 @@ viewable_primitive![
std::num::NonZeroIsize,
std::num::NonZeroUsize,
std::panic::Location<'_>,
std::fmt::Arguments<'_>,
];
cfg_if! {

View File

@ -261,6 +261,17 @@ impl IntoAttribute for Option<Box<dyn IntoAttribute>> {
impl_into_attr_boxed! {}
}
impl IntoAttribute for std::fmt::Arguments<'_> {
fn into_attribute(self) -> Attribute {
match self.as_str() {
Some(s) => s.into_attribute(),
None => self.to_string().into_attribute(),
}
}
impl_into_attr_boxed! {}
}
/* impl IntoAttribute for Box<dyn IntoAttribute> {
#[inline(always)]
fn into_attribute(self) -> Attribute {