FIX: Don not clone Locales and Languages, pass them by reference

This commit is contained in:
Nicolás Hatcher
2025-12-14 16:55:14 +01:00
parent ffe5d1a158
commit 96a5482e01
84 changed files with 308 additions and 251 deletions

View File

@@ -59,9 +59,13 @@ struct DefinedName {
formula: String,
}
fn leak_str(s: &str) -> &'static str {
Box::leak(s.to_owned().into_boxed_str())
}
#[wasm_bindgen]
pub struct Model {
model: BaseModel,
model: BaseModel<'static>,
}
#[wasm_bindgen]
@@ -73,12 +77,17 @@ impl Model {
timezone: &str,
language_id: &str,
) -> Result<Model, JsError> {
let name = leak_str(name);
let locale = leak_str(locale);
let timezone = leak_str(timezone);
let language_id = leak_str(language_id);
let model =
BaseModel::new_empty(name, locale, timezone, language_id).map_err(to_js_error)?;
Ok(Model { model })
}
pub fn from_bytes(bytes: &[u8], language_id: &str) -> Result<Model, JsError> {
let language_id = leak_str(language_id);
let model = BaseModel::from_bytes(bytes, language_id).map_err(to_js_error)?;
Ok(Model { model })
}