From e37ca971bd93a6a5a339aeec9fcd08c8dd1e22fb Mon Sep 17 00:00:00 2001 From: Brian Carroll Date: Sat, 15 Jan 2022 14:38:15 +0000 Subject: [PATCH] Wasm: Simplify CodeBuilder serialization, based on Richard's suggestion --- .../gen_wasm/src/wasm_module/code_builder.rs | 25 +++++-------------- 1 file changed, 6 insertions(+), 19 deletions(-) diff --git a/compiler/gen_wasm/src/wasm_module/code_builder.rs b/compiler/gen_wasm/src/wasm_module/code_builder.rs index fc0f73ca60..ca80469ba7 100644 --- a/compiler/gen_wasm/src/wasm_module/code_builder.rs +++ b/compiler/gen_wasm/src/wasm_module/code_builder.rs @@ -499,26 +499,13 @@ impl<'a> CodeBuilder<'a> { buffer.append_slice(&self.preamble); let mut code_pos = 0; - let mut insert_iter = self.insertions.iter(); - loop { - let next_insert = insert_iter.next(); - let next_pos = match next_insert { - Some(Insertion { at, .. }) => *at, - None => self.code.len(), - }; - - buffer.append_slice(&self.code[code_pos..next_pos]); - - match next_insert { - Some(Insertion { at, start, end }) => { - buffer.append_slice(&self.insert_bytes[*start..*end]); - code_pos = *at; - } - None => { - break; - } - } + for Insertion { at, start, end } in self.insertions.iter() { + buffer.append_slice(&self.code[code_pos..(*at)]); + buffer.append_slice(&self.insert_bytes[*start..*end]); + code_pos = *at; } + + buffer.append_slice(&self.code[code_pos..self.code.len()]); } /// Serialize all byte vectors in the right order