Optimize Module.

This commit is contained in:
Stephen Chung
2022-09-13 18:23:34 +08:00
parent 40a12b2b7d
commit 4be8062924
3 changed files with 284 additions and 166 deletions

View File

@@ -867,13 +867,14 @@ impl Engine {
&& access == AccessMode::ReadOnly
&& lib.iter().any(|&m| !m.is_empty())
{
if global.constants.is_none() {
global.constants = Some(crate::Shared::new(
crate::Locked::new(std::collections::BTreeMap::new()),
));
}
crate::func::locked_write(global.constants.as_ref().unwrap())
.insert(var_name.name.clone(), value.clone());
crate::func::locked_write(global.constants.get_or_insert_with(
|| {
crate::Shared::new(crate::Locked::new(
std::collections::BTreeMap::new(),
))
},
))
.insert(var_name.name.clone(), value.clone());
}
if export {