Skip to content

Commit 13e1881

Browse files
committed
LibJS: Store length of Call instructions in a member variable
This means we don't have to do a bunch of math to find the next instruction boundary, and gives us a small speedup.
1 parent 1e0b565 commit 13e1881

File tree

1 file changed

+12
-16
lines changed
  • Libraries/LibJS/Bytecode

1 file changed

+12
-16
lines changed

Libraries/LibJS/Bytecode/Op.h

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1919,6 +1919,7 @@ class Call final : public Instruction {
19191919

19201920
Call(Operand dst, Operand callee, Operand this_value, ReadonlySpan<ScopedOperand> arguments, Optional<StringTableIndex> expression_string = {})
19211921
: Instruction(Type::Call)
1922+
, m_length(round_up_to_power_of_two(alignof(void*), sizeof(*this) + sizeof(Operand) * arguments.size()))
19221923
, m_dst(dst)
19231924
, m_callee(callee)
19241925
, m_this_value(this_value)
@@ -1930,10 +1931,7 @@ class Call final : public Instruction {
19301931
}
19311932

19321933
size_t length() const { return length_impl(); }
1933-
size_t length_impl() const
1934-
{
1935-
return round_up_to_power_of_two(alignof(void*), sizeof(*this) + sizeof(Operand) * m_argument_count);
1936-
}
1934+
size_t length_impl() const { return m_length; }
19371935

19381936
Operand dst() const { return m_dst; }
19391937
Operand callee() const { return m_callee; }
@@ -1954,6 +1952,7 @@ class Call final : public Instruction {
19541952
}
19551953

19561954
private:
1955+
u32 m_length { 0 };
19571956
Operand m_dst;
19581957
Operand m_callee;
19591958
Operand m_this_value;
@@ -1968,6 +1967,7 @@ class CallBuiltin final : public Instruction {
19681967

19691968
CallBuiltin(Operand dst, Operand callee, Operand this_value, ReadonlySpan<ScopedOperand> arguments, Builtin builtin, Optional<StringTableIndex> expression_string = {})
19701969
: Instruction(Type::CallBuiltin)
1970+
, m_length(round_up_to_power_of_two(alignof(void*), sizeof(*this) + sizeof(Operand) * arguments.size()))
19711971
, m_dst(dst)
19721972
, m_callee(callee)
19731973
, m_this_value(this_value)
@@ -1980,10 +1980,7 @@ class CallBuiltin final : public Instruction {
19801980
}
19811981

19821982
size_t length() const { return length_impl(); }
1983-
size_t length_impl() const
1984-
{
1985-
return round_up_to_power_of_two(alignof(void*), sizeof(*this) + sizeof(Operand) * m_argument_count);
1986-
}
1983+
size_t length_impl() const { return m_length; }
19871984

19881985
Operand dst() const { return m_dst; }
19891986
Operand callee() const { return m_callee; }
@@ -2006,6 +2003,7 @@ class CallBuiltin final : public Instruction {
20062003
}
20072004

20082005
private:
2006+
u32 m_length { 0 };
20092007
Operand m_dst;
20102008
Operand m_callee;
20112009
Operand m_this_value;
@@ -2021,6 +2019,7 @@ class CallConstruct final : public Instruction {
20212019

20222020
CallConstruct(Operand dst, Operand callee, ReadonlySpan<ScopedOperand> arguments, Optional<StringTableIndex> expression_string = {})
20232021
: Instruction(Type::CallConstruct)
2022+
, m_length(round_up_to_power_of_two(alignof(void*), sizeof(*this) + sizeof(Operand) * arguments.size()))
20242023
, m_dst(dst)
20252024
, m_callee(callee)
20262025
, m_argument_count(arguments.size())
@@ -2031,10 +2030,7 @@ class CallConstruct final : public Instruction {
20312030
}
20322031

20332032
size_t length() const { return length_impl(); }
2034-
size_t length_impl() const
2035-
{
2036-
return round_up_to_power_of_two(alignof(void*), sizeof(*this) + sizeof(Operand) * m_argument_count);
2037-
}
2033+
size_t length_impl() const { return m_length; }
20382034

20392035
Operand dst() const { return m_dst; }
20402036
Operand callee() const { return m_callee; }
@@ -2053,6 +2049,7 @@ class CallConstruct final : public Instruction {
20532049
}
20542050

20552051
private:
2052+
u32 m_length { 0 };
20562053
Operand m_dst;
20572054
Operand m_callee;
20582055
u32 m_argument_count { 0 };
@@ -2066,6 +2063,7 @@ class CallDirectEval final : public Instruction {
20662063

20672064
CallDirectEval(Operand dst, Operand callee, Operand this_value, ReadonlySpan<ScopedOperand> arguments, Optional<StringTableIndex> expression_string = {})
20682065
: Instruction(Type::CallDirectEval)
2066+
, m_length(round_up_to_power_of_two(alignof(void*), sizeof(*this) + sizeof(Operand) * arguments.size()))
20692067
, m_dst(dst)
20702068
, m_callee(callee)
20712069
, m_this_value(this_value)
@@ -2077,10 +2075,7 @@ class CallDirectEval final : public Instruction {
20772075
}
20782076

20792077
size_t length() const { return length_impl(); }
2080-
size_t length_impl() const
2081-
{
2082-
return round_up_to_power_of_two(alignof(void*), sizeof(*this) + sizeof(Operand) * m_argument_count);
2083-
}
2078+
size_t length_impl() const { return m_length; }
20842079

20852080
Operand dst() const { return m_dst; }
20862081
Operand callee() const { return m_callee; }
@@ -2101,6 +2096,7 @@ class CallDirectEval final : public Instruction {
21012096
}
21022097

21032098
private:
2099+
u32 m_length { 0 };
21042100
Operand m_dst;
21052101
Operand m_callee;
21062102
Operand m_this_value;

0 commit comments

Comments
 (0)