mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 01:17:35 +00:00
LibJS: Streamline InstructionStreamIterator
Nuke all the per-instruction bounds checking when iterating instructions by using raw pointers instead of indexing into a ReadonlyBytes. The interpreter loop already checks that we're in-bounds anyway.
This commit is contained in:
parent
213b835b57
commit
031ec98803
1 changed files with 10 additions and 13 deletions
|
@ -158,35 +158,32 @@ private:
|
||||||
class InstructionStreamIterator {
|
class InstructionStreamIterator {
|
||||||
public:
|
public:
|
||||||
InstructionStreamIterator(ReadonlyBytes bytes, Executable const* executable = nullptr)
|
InstructionStreamIterator(ReadonlyBytes bytes, Executable const* executable = nullptr)
|
||||||
: m_bytes(bytes)
|
: m_begin(bytes.data())
|
||||||
|
, m_end(bytes.data() + bytes.size())
|
||||||
|
, m_ptr(bytes.data())
|
||||||
, m_executable(executable)
|
, m_executable(executable)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t offset() const { return m_offset; }
|
size_t offset() const { return m_ptr - m_begin; }
|
||||||
bool at_end() const { return m_offset >= m_bytes.size(); }
|
bool at_end() const { return m_ptr >= m_end; }
|
||||||
void jump(size_t offset)
|
|
||||||
{
|
|
||||||
VERIFY(offset <= m_bytes.size());
|
|
||||||
m_offset = offset;
|
|
||||||
}
|
|
||||||
|
|
||||||
Instruction const& operator*() const { return dereference(); }
|
Instruction const& operator*() const { return dereference(); }
|
||||||
|
|
||||||
ALWAYS_INLINE void operator++()
|
ALWAYS_INLINE void operator++()
|
||||||
{
|
{
|
||||||
VERIFY(!at_end());
|
m_ptr += dereference().length();
|
||||||
m_offset += dereference().length();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
UnrealizedSourceRange source_range() const;
|
UnrealizedSourceRange source_range() const;
|
||||||
RefPtr<SourceCode> source_code() const;
|
RefPtr<SourceCode> source_code() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Instruction const& dereference() const { return *reinterpret_cast<Instruction const*>(m_bytes.data() + offset()); }
|
Instruction const& dereference() const { return *reinterpret_cast<Instruction const*>(m_ptr); }
|
||||||
|
|
||||||
ReadonlyBytes m_bytes;
|
u8 const* m_begin { nullptr };
|
||||||
size_t m_offset { 0 };
|
u8 const* m_end { nullptr };
|
||||||
|
u8 const* m_ptr { nullptr };
|
||||||
Executable const* m_executable { nullptr };
|
Executable const* m_executable { nullptr };
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue