(mc: &Mutation<'gc>, s: &[u8])
| 81 | // buffer. This can be improved when gc-arena learns to allocate variable sizes. |
| 82 | |
| 83 | fn create<'gc, const N: usize>(mc: &Mutation<'gc>, s: &[u8]) -> InternedString<'gc> { |
| 84 | #[derive(Collect)] |
| 85 | #[collect(require_static)] |
| 86 | #[repr(C)] |
| 87 | struct InlineString<const N: usize> { |
| 88 | header: StringInner, |
| 89 | array: [u8; N], |
| 90 | } |
| 91 | |
| 92 | assert!(s.len() <= N); |
| 93 | let mut string = InlineString { |
| 94 | header: StringInner { |
| 95 | hash: str_hash(s), |
| 96 | buffer: Buffer::Inline(s.len()), |
| 97 | }, |
| 98 | array: [0; N], |
| 99 | }; |
| 100 | string.array[0..s.len()].copy_from_slice(s); |
| 101 | |
| 102 | let string = Gc::new(mc, string); |
| 103 | // SAFETY: We know we can cast to `StringInner` because `InlineString` is `#[repr(C)]` |
| 104 | // and `header` is the first field. |
| 105 | unsafe { InternedString(Gc::cast::<StringInner>(string)) } |
| 106 | } |
| 107 | |
| 108 | let s = s.as_ref(); |
| 109 |
no test coverage detected