Commit c0564971 authored by Toon Verwaest's avatar Toon Verwaest Committed by Commit Bot

[parser] Use SmallVector(1) for DeclarationParsingResult::declarations

Typically we'll parse a single declaration when parsing variable declarations.
Using on-stack storage rather than std::vector that requires malloc is much
more efficient.

Change-Id: Id99515bb4ce7ea2dae46498f8f9f9d49c33c7353
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2418393
Commit-Queue: Toon Verwaest <verwaest@chromium.org>
Reviewed-by: 's avatarLeszek Swirski <leszeks@chromium.org>
Cr-Commit-Position: refs/heads/master@{#69995}
parent 0c1b530b
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#define V8_PARSING_PARSER_BASE_H_ #define V8_PARSING_PARSER_BASE_H_
#include <stdint.h> #include <stdint.h>
#include <utility> #include <utility>
#include <vector> #include <vector>
...@@ -14,6 +15,7 @@ ...@@ -14,6 +15,7 @@
#include "src/ast/scopes.h" #include "src/ast/scopes.h"
#include "src/base/flags.h" #include "src/base/flags.h"
#include "src/base/hashmap.h" #include "src/base/hashmap.h"
#include "src/base/small-vector.h"
#include "src/base/v8-fallthrough.h" #include "src/base/v8-fallthrough.h"
#include "src/codegen/bailout-reason.h" #include "src/codegen/bailout-reason.h"
#include "src/common/globals.h" #include "src/common/globals.h"
...@@ -539,14 +541,17 @@ class ParserBase { ...@@ -539,14 +541,17 @@ class ParserBase {
struct DeclarationParsingResult { struct DeclarationParsingResult {
struct Declaration { struct Declaration {
Declaration(ExpressionT pattern, ExpressionT initializer) Declaration(ExpressionT pattern, ExpressionT initializer,
: pattern(pattern), initializer(initializer) { int value_beg_pos = kNoSourcePosition)
: pattern(pattern),
initializer(initializer),
value_beg_pos(value_beg_pos) {
DCHECK_IMPLIES(Impl::IsNull(pattern), Impl::IsNull(initializer)); DCHECK_IMPLIES(Impl::IsNull(pattern), Impl::IsNull(initializer));
} }
ExpressionT pattern; ExpressionT pattern;
ExpressionT initializer; ExpressionT initializer;
int value_beg_pos = kNoSourcePosition; int value_beg_pos;
}; };
DeclarationParsingResult() DeclarationParsingResult()
...@@ -554,7 +559,7 @@ class ParserBase { ...@@ -554,7 +559,7 @@ class ParserBase {
bindings_loc(Scanner::Location::invalid()) {} bindings_loc(Scanner::Location::invalid()) {}
DeclarationDescriptor descriptor; DeclarationDescriptor descriptor;
std::vector<Declaration> declarations; base::SmallVector<Declaration, 1> declarations;
Scanner::Location first_initializer_loc; Scanner::Location first_initializer_loc;
Scanner::Location bindings_loc; Scanner::Location bindings_loc;
}; };
...@@ -3929,10 +3934,7 @@ void ParserBase<Impl>::ParseVariableDeclarations( ...@@ -3929,10 +3934,7 @@ void ParserBase<Impl>::ParseVariableDeclarations(
impl()->IsNull(value) || impl()->IsNull(value) ||
(var_context == kForStatement && PeekInOrOf())); (var_context == kForStatement && PeekInOrOf()));
typename DeclarationParsingResult::Declaration decl(pattern, value); parsing_result->declarations.emplace_back(pattern, value, value_beg_pos);
decl.value_beg_pos = value_beg_pos;
parsing_result->declarations.push_back(decl);
} while (Check(Token::COMMA)); } while (Check(Token::COMMA));
parsing_result->bindings_loc = parsing_result->bindings_loc =
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment