Skip to content

Commit f365586

Browse files
committed
Try using bytes instead of vector<uint8_t>
1 parent d3f0e65 commit f365586

File tree

3 files changed

+6
-7
lines changed

3 files changed

+6
-7
lines changed

lib/fizzy/parser_expr.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ inline void store(uint8_t* dst, T value) noexcept
2020
}
2121

2222
template <typename T>
23-
inline void push(std::vector<uint8_t>& b, T value)
23+
inline void push(bytes& b, T value)
2424
{
2525
uint8_t storage[sizeof(T)];
2626
store(storage, value);
@@ -198,8 +198,7 @@ inline void update_branch_stack(const ControlFrame& current_frame, const Control
198198
drop_operand(current_frame, operand_stack, from_valtype(*branch_frame_type));
199199
}
200200

201-
void push_branch_immediates(
202-
const ControlFrame& branch_frame, int stack_height, std::vector<uint8_t>& instructions)
201+
void push_branch_immediates(const ControlFrame& branch_frame, int stack_height, bytes& instructions)
203202
{
204203
// How many stack items to drop when taking the branch.
205204
const auto stack_drop = stack_height - branch_frame.parent_stack_height;
@@ -872,7 +871,7 @@ parser_result<Code> parse_expr(const uint8_t* pos, const uint8_t* end, FuncIdx f
872871
break;
873872
}
874873
}
875-
code.instructions.emplace_back(opcode);
874+
code.instructions.push_back(opcode);
876875
}
877876
assert(control_stack.empty());
878877
return {code, pos};

lib/fizzy/types.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ struct Code
362362

363363
// The instructions bytecode without immediate values.
364364
// https://webassembly.github.io/spec/core/binary/instructions.html
365-
std::vector<uint8_t> instructions;
365+
bytes instructions;
366366
};
367367

368368
/// The reference to the `code` in the wasm binary.

test/unittests/execute_death_test.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ TEST(execute_death, malformed_instruction_opcode)
1414
constexpr uint8_t malformed_opcode = 6;
1515

1616
Code code;
17-
code.instructions.emplace_back(malformed_opcode);
18-
code.instructions.emplace_back(static_cast<uint8_t>(Instr::end));
17+
code.instructions.push_back(malformed_opcode);
18+
code.instructions.push_back(static_cast<uint8_t>(Instr::end));
1919

2020
auto module = std::make_unique<Module>();
2121
module->typesec.emplace_back(FuncType{});

0 commit comments

Comments
 (0)