-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
yew-macro
: optimise macros' memory usage
#3845
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
use std::fmt::{Display, Write}; | ||
|
||
use proc_macro2::Span; | ||
use quote::{quote, quote_spanned, ToTokens}; | ||
use syn::parse::discouraged::Speculative; | ||
|
@@ -9,6 +11,41 @@ use super::{HtmlChildrenTree, TagTokens}; | |
use crate::is_ide_completion; | ||
use crate::props::ComponentProps; | ||
|
||
/// Returns `true` if `s` looks like a component name | ||
pub fn is_component_name(s: impl Display) -> bool { | ||
struct X { | ||
is_ide_completion: bool, | ||
empty: bool, | ||
} | ||
|
||
impl Write for X { | ||
fn write_str(&mut self, chunk: &str) -> std::fmt::Result { | ||
if self.empty { | ||
self.empty = chunk.is_empty(); | ||
if !self.is_ide_completion | ||
&& chunk | ||
.bytes() | ||
.next() | ||
.is_some_and(|b| !b.is_ascii_uppercase()) | ||
{ | ||
return Err(std::fmt::Error); | ||
} | ||
} | ||
chunk | ||
.bytes() | ||
.any(|b| b.is_ascii_uppercase()) | ||
.then_some(()) | ||
.ok_or(std::fmt::Error) | ||
} | ||
} | ||
|
||
let mut writer = X { | ||
is_ide_completion: is_ide_completion(), | ||
empty: true, | ||
}; | ||
write!(writer, "{s}").is_ok_and(|_| !writer.empty) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This deserves a better comment and improved naming, as it is very hard to follow currently. A name is, at the moment, assumed to be a component name if it
Both of these are rough approximations, for example I think the second condition could be changed to match a specific identifier passed via the |
||
} | ||
|
||
pub struct HtmlComponent { | ||
ty: Type, | ||
props: ComponentProps, | ||
|
Uh oh!
There was an error while loading. Please reload this page.