mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-30 15:21:12 +00:00
Slightly refactor code section swapping
This commit is contained in:
parent
f066adbe05
commit
eb47b5183c
1 changed files with 9 additions and 6 deletions
|
@ -107,12 +107,15 @@ pub fn build_module_help<'a>(
|
||||||
/// Replace parity-wasm's code section with our own handmade one
|
/// Replace parity-wasm's code section with our own handmade one
|
||||||
pub fn replace_code_section(module: &mut Module, code_section_bytes: std::vec::Vec<u8>) {
|
pub fn replace_code_section(module: &mut Module, code_section_bytes: std::vec::Vec<u8>) {
|
||||||
let sections = module.sections_mut();
|
let sections = module.sections_mut();
|
||||||
let mut code_section_index = usize::MAX;
|
|
||||||
for (i, s) in sections.iter().enumerate() {
|
let code_section_index = sections
|
||||||
if let Section::Code(_) = s {
|
.iter()
|
||||||
code_section_index = i;
|
.position(|s| match s {
|
||||||
}
|
Section::Code(_) => true,
|
||||||
}
|
_ => false,
|
||||||
|
})
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
sections[code_section_index] = Section::Unparsed {
|
sections[code_section_index] = Section::Unparsed {
|
||||||
id: CODE_SECTION_ID,
|
id: CODE_SECTION_ID,
|
||||||
payload: code_section_bytes,
|
payload: code_section_bytes,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue