1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 19:57:35 +00:00

LibJS: Always inline the bytecode instruction iterator's operator++

This commit is contained in:
Andreas Kling 2021-10-25 13:37:02 +02:00
parent a97d75bb63
commit d203a86900
3 changed files with 32 additions and 31 deletions

View file

@ -64,10 +64,4 @@ void BasicBlock::grow(size_t additional_size)
VERIFY(m_buffer_size <= m_buffer_capacity);
}
void InstructionStreamIterator::operator++()
{
VERIFY(!at_end());
m_offset += dereference().length();
}
}

View file

@ -13,31 +13,6 @@
namespace JS::Bytecode {
class InstructionStreamIterator {
public:
explicit InstructionStreamIterator(ReadonlyBytes bytes)
: m_bytes(bytes)
{
}
size_t offset() const { return m_offset; }
bool at_end() const { return m_offset >= m_bytes.size(); }
void jump(size_t offset)
{
VERIFY(offset <= m_bytes.size());
m_offset = offset;
}
Instruction const& operator*() const { return dereference(); }
void operator++();
private:
Instruction const& dereference() const { return *reinterpret_cast<Instruction const*>(m_bytes.data() + offset()); }
ReadonlyBytes m_bytes;
size_t m_offset { 0 };
};
struct UnwindInfo {
Executable const* executable;
BasicBlock const* handler;

View file

@ -7,6 +7,7 @@
#pragma once
#include <AK/Forward.h>
#include <AK/Span.h>
#include <LibJS/Forward.h>
#define ENUMERATE_BYTECODE_OPS(O) \
@ -106,4 +107,35 @@ protected:
private:
Type m_type {};
};
class InstructionStreamIterator {
public:
explicit InstructionStreamIterator(ReadonlyBytes bytes)
: m_bytes(bytes)
{
}
size_t offset() const { return m_offset; }
bool at_end() const { return m_offset >= m_bytes.size(); }
void jump(size_t offset)
{
VERIFY(offset <= m_bytes.size());
m_offset = offset;
}
Instruction const& operator*() const { return dereference(); }
ALWAYS_INLINE void operator++()
{
VERIFY(!at_end());
m_offset += dereference().length();
}
private:
Instruction const& dereference() const { return *reinterpret_cast<Instruction const*>(m_bytes.data() + offset()); }
ReadonlyBytes m_bytes;
size_t m_offset { 0 };
};
}