diff --git a/crates/runtime/src/cow.rs b/crates/runtime/src/cow.rs index b81a184783..7cd2987d1a 100644 --- a/crates/runtime/src/cow.rs +++ b/crates/runtime/src/cow.rs @@ -27,7 +27,7 @@ impl ModuleMemoryImages { } /// One backing image for one memory. -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct MemoryImage { /// The file descriptor source of this image. /// @@ -75,6 +75,12 @@ impl FdSource { } } +impl PartialEq for FdSource { + fn eq(&self, other: &FdSource) -> bool { + self.as_file().as_raw_fd() == other.as_file().as_raw_fd() + } +} + impl MemoryImage { fn new( page_size: u32, @@ -348,14 +354,7 @@ impl MemoryImageSlot { // termination. The `clear_and_remain_ready()` path also // mprotects memory above the initial heap size back to // PROT_NONE, so we don't need to do that here. - if (self.image.is_none() - && maybe_image.is_none() - && self.initial_size == initial_size_bytes) - || (self.image.is_some() - && maybe_image.is_some() - && self.image.as_ref().unwrap().fd.as_file().as_raw_fd() - == maybe_image.as_ref().unwrap().fd.as_file().as_raw_fd()) - { + if self.image.as_ref() == maybe_image && self.initial_size == initial_size_bytes { self.dirty = true; return Ok(()); }