fix miscompilation for wasm

This commit is contained in:
Folkert 2022-03-18 23:11:11 +01:00
parent 813b22a106
commit 988ab8775b
No known key found for this signature in database
GPG key ID: 1F17F6FFD112B97C
2 changed files with 10 additions and 11 deletions

View file

@ -5,6 +5,7 @@ use core::convert::From;
use core::{fmt, mem, ptr, slice};
use std::alloc::{alloc, dealloc, Layout};
use std::os::raw::c_char;
use std::str::FromStr;
/// A string which can store identifiers using the small string optimization.
/// It relies on the invariant that it cannot store null characters to store
@ -102,13 +103,8 @@ impl IdentStr {
unsafe { mem::transmute::<[u8; mem::size_of::<Self>()], Self>(bytes) }
}
pub fn from_array_string(
array_string: arrayvec::ArrayString<{ Self::SMALL_STR_BYTES }>,
) -> Self {
Self::small_str_from_bytes(array_string.as_bytes())
}
fn from_str(str: &str) -> Self {
#[allow(clippy::should_implement_trait)]
pub fn from_str(str: &str) -> Self {
let slice = str.as_bytes();
let len = slice.len();

View file

@ -636,12 +636,15 @@ impl IdentIds {
pub fn gen_unique(&mut self) -> IdentId {
use std::fmt::Write;
let mut temp: arrayvec::ArrayString<15> = arrayvec::ArrayString::new();
write!(temp, "{}", self.next_generated_name).unwrap();
let ident = Ident(IdentStr::from_array_string(temp));
let index: u32 = self.next_generated_name;
self.next_generated_name += 1;
// "4294967296" is 10 characters
let mut buffer: arrayvec::ArrayString<10> = arrayvec::ArrayString::new();
write!(buffer, "{}", index).unwrap();
let ident = Ident(IdentStr::from_str(buffer.as_str()));
self.add(ident)
}