From 0d1946a7821d3aab70b77dba4fd367f728cded81 Mon Sep 17 00:00:00 2001 From: Brian Carroll Date: Thu, 4 Nov 2021 20:50:32 +0000 Subject: [PATCH] Don't generate a DataSection unless we actually need it! --- compiler/gen_wasm/src/wasm_module/sections.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/compiler/gen_wasm/src/wasm_module/sections.rs b/compiler/gen_wasm/src/wasm_module/sections.rs index 27f8d8ff45..782a97b043 100644 --- a/compiler/gen_wasm/src/wasm_module/sections.rs +++ b/compiler/gen_wasm/src/wasm_module/sections.rs @@ -516,7 +516,10 @@ impl<'a> DataSection<'a> { impl Serialize for DataSection<'_> { fn serialize(&self, buffer: &mut T) { - serialize_vector_section(buffer, SectionId::Data, &self.segments); + let total_payload_size = self.segments.iter().map(|seg| seg.init.len()).sum(); + if total_payload_size > 0 { + serialize_vector_section(buffer, SectionId::Data, &self.segments); + } } }