Code review feedback.

* Improve comments.
* Drop old table element *after* updating the table.
* Extract out the same `cfg_if!` to a single constant.
This commit is contained in:
Peter Huene
2021-03-08 09:04:13 -08:00
parent 8e51aefb2c
commit 7a93132ffa
4 changed files with 19 additions and 25 deletions

View File

@@ -307,6 +307,8 @@ impl Module {
/// # }
/// ```
pub fn from_binary(engine: &Engine, binary: &[u8]) -> Result<Module> {
const USE_PAGED_MEM_INIT: bool = cfg!(all(feature = "uffd", target_os = "linux"));
cfg_if::cfg_if! {
if #[cfg(feature = "cache")] {
let (main_module, artifacts, types) = ModuleCacheEntry::new(
@@ -314,27 +316,11 @@ impl Module {
engine.cache_config(),
)
.get_data((engine.compiler(), binary), |(compiler, binary)| {
cfg_if::cfg_if! {
if #[cfg(all(feature = "uffd", target_os = "linux"))] {
let use_paged_mem_init = true;
} else {
let use_paged_mem_init = false;
}
};
CompilationArtifacts::build(compiler, binary, use_paged_mem_init)
CompilationArtifacts::build(compiler, binary, USE_PAGED_MEM_INIT)
})?;
} else {
cfg_if::cfg_if! {
if #[cfg(all(feature = "uffd", target_os = "linux"))] {
let use_paged_mem_init = true;
} else {
let use_paged_mem_init = false;
}
};
let (main_module, artifacts, types) =
CompilationArtifacts::build(engine.compiler(), binary, use_paged_mem_init)?;
CompilationArtifacts::build(engine.compiler(), binary, USE_PAGED_MEM_INIT)?;
}
};