Skip to content

Commit 80a0fc6

Browse files
committed
factor out parsing of code section entries
1 parent 267840d commit 80a0fc6

1 file changed

Lines changed: 20 additions & 9 deletions

File tree

crates/wasmi/src/module/parser/buffered.rs

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -120,15 +120,7 @@ impl ModuleParser {
120120
header: ModuleHeader,
121121
mut custom_sections: CustomSectionsBuilder,
122122
) -> Result<Module, Error> {
123-
let mut payload;
124-
'exit: loop {
125-
payload = self.next_payload(buffer)?;
126-
let Payload::CodeSectionEntry(func_body) = payload else {
127-
break 'exit;
128-
};
129-
let bytes = func_body.as_bytes();
130-
self.process_code_entry(func_body, bytes, &header)?;
131-
}
123+
let mut payload = self.parse_buffered_code_entries(buffer, &header)?;
132124
loop {
133125
match payload {
134126
Payload::CustomSection(reader) => {
@@ -146,6 +138,25 @@ impl ModuleParser {
146138
}
147139
}
148140

141+
/// Parse the Wasm section code entries.
142+
///
143+
/// Returns the next payload after the last code section entry.
144+
fn parse_buffered_code_entries<'a>(
145+
&mut self,
146+
buffer: &mut &'a [u8],
147+
header: &ModuleHeader,
148+
) -> Result<Payload<'a>, Error> {
149+
loop {
150+
match self.next_payload(buffer)? {
151+
Payload::CodeSectionEntry(func_body) => {
152+
let bytes = func_body.as_bytes();
153+
self.process_code_entry(func_body, bytes, header)?;
154+
}
155+
other => return Ok(other),
156+
}
157+
}
158+
}
159+
149160
/// Parse post the Wasm data section and finalize parsing.
150161
///
151162
/// We separate parsing of the Wasm data section since it is the only Wasm

0 commit comments

Comments
 (0)