mirror of
https://github.com/oxc-project/oxc.git
synced 2026-11-04 10:29:58 +00:00
perf(str): static_ident! and static_str! macros guarantee const evaluation (#28340)
`static_ident!` and `static_str!` macros are intended to evaluate at compile time. This is especially valuable for `static_ident!` as we want the hash to be calculated at compile time.
Wrap both in a `const { ... }` block to ensure they are const-evaluated.
This commit is contained in:
1 parent
df908363ec
commit
2683225190
2 files changed
+4
-2
No files matched your search
@@ -581,7 +581,8 @@ pub type ArenaIdentHashSet<'alloc> =
|
||||
#[macro_export]
|
||||
macro_rules! static_ident {
|
||||
($s:literal) => {
|
||||
$crate::__internal::new_const_ident($s)
|
||||
// `const { ... }` block guarantees evaluation at compile time
|
||||
const { $crate::__internal::new_const_ident($s) }
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -341,7 +341,8 @@ impl ESTree for Str<'_> {
|
||||
#[macro_export]
|
||||
macro_rules! static_str {
|
||||
($s:literal) => {
|
||||
$crate::Str::new_const($s)
|
||||
// `const { ... }` block guarantees evaluation at compile time
|
||||
const { $crate::Str::new_const($s) }
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user