Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf(fe): reduce size of Call and Index expressions #1163

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 35 additions & 6 deletions src/quick-lint-js/fe/expression.h
Original file line number Diff line number Diff line change
Expand Up @@ -613,24 +613,38 @@ class Expression::Call final : public Expression {

explicit Call(Expression_Arena::Array_Ptr<Expression *> children,
Source_Code_Span left_paren_span, const Char8 *span_end,
std::optional<Source_Code_Span> optional_chaining_op_)
std::optional<Source_Code_Span> optional_chaining_operator)
: Expression(kind),
call_left_paren_begin_(left_paren_span.begin()),
span_end_(span_end),
children_(children),
optional_chaining_operator_(optional_chaining_op_) {
optional_chaining_operator_begin_(
optional_chaining_operator.has_value()
? optional_chaining_operator->begin()
: nullptr) {
QLJS_ASSERT(left_paren_span.size() == 1);
if (optional_chaining_operator.has_value()) {
QLJS_ASSERT(optional_chaining_operator->size() == 2);
}
}

Source_Code_Span left_paren_span() const {
return Source_Code_Span(this->call_left_paren_begin_,
this->call_left_paren_begin_ + 1);
}

std::optional<Source_Code_Span> optional_chaining_operator_span() const {
if (this->optional_chaining_operator_begin_ == nullptr) {
return std::nullopt;
}
return Source_Code_Span(this->optional_chaining_operator_begin_,
this->optional_chaining_operator_begin_ + 2);
}

const Char8 *call_left_paren_begin_;
const Char8 *span_end_;
Expression_Arena::Array_Ptr<Expression *> children_;
std::optional<Source_Code_Span> optional_chaining_operator_;
const Char8 *optional_chaining_operator_begin_ = nullptr;
};
static_assert(Expression_Arena::is_allocatable<Expression::Call>);

Expand Down Expand Up @@ -690,17 +704,32 @@ class Expression::Index final : public Expression {

explicit Index(Expression *container, Expression *subscript,
Source_Code_Span left_square_span, const Char8 *subscript_end,
std::optional<Source_Code_Span> optional_chaining_op_)
std::optional<Source_Code_Span> optional_chaining_operator)
: Expression(kind),
index_subscript_end_(subscript_end),
left_square_span(left_square_span),
children_{container, subscript},
optional_chaining_operator_(optional_chaining_op_) {}
optional_chaining_operator_begin_(
optional_chaining_operator.has_value()
? optional_chaining_operator->begin()
: nullptr) {
if (optional_chaining_operator.has_value()) {
QLJS_ASSERT(optional_chaining_operator->size() == 2);
}
}

std::optional<Source_Code_Span> optional_chaining_operator_span() const {
if (this->optional_chaining_operator_begin_ == nullptr) {
return std::nullopt;
}
return Source_Code_Span(this->optional_chaining_operator_begin_,
this->optional_chaining_operator_begin_ + 2);
}

const Char8 *index_subscript_end_;
Source_Code_Span left_square_span;
std::array<Expression *, 2> children_;
std::optional<Source_Code_Span> optional_chaining_operator_;
const Char8 *optional_chaining_operator_begin_;
};
static_assert(Expression_Arena::is_allocatable<Expression::Index>);

Expand Down
4 changes: 2 additions & 2 deletions src/quick-lint-js/fe/parse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ void Parser::warn_on_dot_operator_after_optional_chain(Expression::Dot* ast) {
case Expression_Kind::Call: {
auto lhs_call = expression_cast<Expression::Call*>(lhs);
std::optional<Source_Code_Span> lhs_operator_span =
lhs_call->optional_chaining_operator_;
lhs_call->optional_chaining_operator_span();
if (lhs_operator_span.has_value()) {
this->diag_reporter_->report(Diag_Using_Dot_After_Optional_Chaining{
.dot_op = operator_span,
Expand All @@ -505,7 +505,7 @@ void Parser::warn_on_dot_operator_after_optional_chain(Expression::Dot* ast) {
case Expression_Kind::Index: {
auto lhs_index = expression_cast<Expression::Index*>(lhs);
std::optional<Source_Code_Span> lhs_operator_span =
lhs_index->optional_chaining_operator_;
lhs_index->optional_chaining_operator_span();
if (lhs_operator_span.has_value()) {
this->diag_reporter_->report(Diag_Using_Dot_After_Optional_Chaining{
.dot_op = operator_span,
Expand Down
Loading