11use std:: {
2+ alloc:: GlobalAlloc ,
23 borrow:: { Borrow , Cow } ,
34 ffi:: OsStr ,
45 fmt:: { Debug , Display } ,
@@ -11,6 +12,7 @@ use std::{
1112
1213use bytes_str:: BytesStr ;
1314use debug_unreachable:: debug_unreachable;
15+ use napi:: threadsafe_function:: ErrorStrategy :: T ;
1416use serde:: { Deserialize , Deserializer , Serialize , Serializer } ;
1517use shrink_to_fit:: ShrinkToFit ;
1618use triomphe:: Arc ;
@@ -382,7 +384,7 @@ pub use dynamic::{PrehashedString, hash_bytes};
382384
383385#[ doc( hidden) ]
384386impl RcStr {
385- // Allow the rcstr! macro to skip a tag branch
387+ // Allow the rcstr! macro to skip a tag branch and just copy the struct
386388 #[ doc( hidden) ]
387389 pub fn unsafe_copy_for_macro ( & self ) -> RcStr {
388390 debug_assert ! ( self . tag( ) == STATIC_TAG ) ;
@@ -407,6 +409,14 @@ macro_rules! rcstr {
407409 // Allocate static storage for the PrehashedString
408410 static INNER : :: std:: sync:: LazyLock <$crate:: PrehashedString > =
409411 :: std:: sync:: LazyLock :: new( || $crate:: PrehashedString {
412+ // `String::from_raw_parts`` would be a pretty legit option here since
413+ // we could const allocate this. However, we would need to:
414+ // * cast the static str to a *mut u8
415+ // * convince ourselves that the admonitions to supply allocator allocated
416+ // pointers are only about drop.
417+ // Alternatively we could transmute a Vec allocated from from_raw_parts_in
418+ // using an allocator that never frees.
419+ // For how we just copy and allocate
410420 value: $s. into( ) ,
411421 // compute the hash at compile time
412422 hash: const { $crate:: hash_bytes( $s. as_bytes( ) ) } ,
0 commit comments