Wasm: Simplify CodeBuilder serialization, based on Richard's suggestion

This commit is contained in:
Brian Carroll 2022-01-15 14:38:15 +00:00
parent 54e820620a
commit e37ca971bd

View file

@ -499,26 +499,13 @@ impl<'a> CodeBuilder<'a> {
buffer.append_slice(&self.preamble); buffer.append_slice(&self.preamble);
let mut code_pos = 0; let mut code_pos = 0;
let mut insert_iter = self.insertions.iter(); for Insertion { at, start, end } in self.insertions.iter() {
loop { buffer.append_slice(&self.code[code_pos..(*at)]);
let next_insert = insert_iter.next(); buffer.append_slice(&self.insert_bytes[*start..*end]);
let next_pos = match next_insert { code_pos = *at;
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;
}
}
} }
buffer.append_slice(&self.code[code_pos..self.code.len()]);
} }
/// Serialize all byte vectors in the right order /// Serialize all byte vectors in the right order