Skip to content

Commit

Permalink
Initialize ArrayList with expected size whenever possible.
Browse files Browse the repository at this point in the history
  • Loading branch information
traceyyoshima committed Nov 17, 2023
1 parent 5a81c7e commit d170cdf
Showing 1 changed file with 9 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,10 @@ public TypeScriptParserVisitor(TSCNode source, TSCSourceFileContext sourceContex
}

public JS.CompilationUnit visitSourceFile() {
List<JRightPadded<Statement>> statements = new ArrayList<>();
TSCNodeList statementList = source.getNodeListProperty("statements");
List<JRightPadded<Statement>> statements = new ArrayList<>(statementList.size());
Space prefix = whitespace();
for (TSCNode child : source.getNodeListProperty("statements")) {
for (TSCNode child : statementList) {
@Nullable J visited;
int saveCursor = getCursor();
try {
Expand Down Expand Up @@ -243,7 +244,7 @@ private J.NewArray visitArrayLiteralExpression(TSCNode node) {
this::visitNode,
true
);
List<JRightPadded<Expression>> elements = new ArrayList<>();
List<JRightPadded<Expression>> elements = new ArrayList<>(jContainer.getElements().size());
for (JRightPadded<J> jjRightPadded : jContainer.getPadding().getElements()) {
Expression exp = (!(jjRightPadded.getElement() instanceof Expression) && jjRightPadded.getElement() instanceof Statement) ?
new JS.StatementExpression(randomId(), (Statement) jjRightPadded.getElement()) : (Expression) jjRightPadded.getElement();
Expand Down Expand Up @@ -554,7 +555,7 @@ private J.MethodInvocation visitCallExpression(TSCNode node) {
true
);

List<JRightPadded<Expression>> typeParams = new ArrayList<>();
List<JRightPadded<Expression>> typeParams = new ArrayList<>(jContainer.getElements().size());
for (JRightPadded<J> jjRightPadded : jContainer.getPadding().getElements()) {
Expression exp = (!(jjRightPadded.getElement() instanceof Expression) && jjRightPadded.getElement() instanceof Statement) ?
new JS.StatementExpression(randomId(), (Statement) jjRightPadded.getElement()) : (Expression) jjRightPadded.getElement();
Expand All @@ -574,7 +575,7 @@ private J.MethodInvocation visitCallExpression(TSCNode node) {
this::visitNode,
true
);
List<JRightPadded<Expression>> elements = new ArrayList<>();
List<JRightPadded<Expression>> elements = new ArrayList<>(jContainer.getElements().size());
for (JRightPadded<J> jjRightPadded : jContainer.getPadding().getElements()) {
Expression exp = (!(jjRightPadded.getElement() instanceof Expression) && jjRightPadded.getElement() instanceof Statement) ?
new JS.StatementExpression(randomId(), (Statement) jjRightPadded.getElement()) : (Expression) jjRightPadded.getElement();
Expand Down Expand Up @@ -842,7 +843,7 @@ private J.Annotation visitDecorator(TSCNode node) {
true
);

List<JRightPadded<Expression>> elements = new ArrayList<>();
List<JRightPadded<Expression>> elements = new ArrayList<>(jContainer.getElements().size());
for (JRightPadded<J> jjRightPadded : jContainer.getPadding().getElements()) {
Expression exp = (!(jjRightPadded.getElement() instanceof Expression) && jjRightPadded.getElement() instanceof Statement) ?
new JS.StatementExpression(randomId(), (Statement) jjRightPadded.getElement()) : (Expression) jjRightPadded.getElement();
Expand Down Expand Up @@ -1644,7 +1645,7 @@ private J.NewClass visitNewExpression(TSCNode node) {
this::visitNode,
true
);
List<JRightPadded<Expression>> elements = new ArrayList<>();
List<JRightPadded<Expression>> elements = new ArrayList<>(jContainer.getElements().size());
for (JRightPadded<J> jjRightPadded : jContainer.getPadding().getElements()) {
Expression exp = (!(jjRightPadded.getElement() instanceof Expression) && jjRightPadded.getElement() instanceof Statement) ?
new JS.StatementExpression(randomId(), (Statement) jjRightPadded.getElement()) : (Expression) jjRightPadded.getElement();
Expand Down Expand Up @@ -1695,7 +1696,7 @@ private J visitObjectLiteralExpression(TSCNode node) {
if (jContainer.getElements().isEmpty()) {
arguments = JContainer.empty();
} else {
List<JRightPadded<Expression>> elements = new ArrayList<>();
List<JRightPadded<Expression>> elements = new ArrayList<>(jContainer.getElements().size());
for (JRightPadded<J> jjRightPadded : jContainer.getPadding().getElements()) {
Expression exp = (!(jjRightPadded.getElement() instanceof Expression) && jjRightPadded.getElement() instanceof Statement) ?
new JS.StatementExpression(randomId(), (Statement) jjRightPadded.getElement()) : (Expression) jjRightPadded.getElement();
Expand Down

0 comments on commit d170cdf

Please sign in to comment.