From a34439de42266b9d88de869460be9b5dc1c7fb20 Mon Sep 17 00:00:00 2001 From: vms Date: Fri, 25 Oct 2019 01:56:04 +0300 Subject: [PATCH] optimize memory.grow 0 (#443) --- wasmtime-runtime/src/memory.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/wasmtime-runtime/src/memory.rs b/wasmtime-runtime/src/memory.rs index 121cbc34a2..fca4b384be 100644 --- a/wasmtime-runtime/src/memory.rs +++ b/wasmtime-runtime/src/memory.rs @@ -80,6 +80,11 @@ impl LinearMemory { /// Returns `None` if memory can't be grown by the specified amount /// of wasm pages. pub fn grow(&mut self, delta: u32) -> Option { + // Optimization of memory.grow 0 calls. + if delta == 0 { + return Some(self.current); + } + let new_pages = match self.current.checked_add(delta) { Some(new_pages) => new_pages, // Linear memory size overflow.