From d863c02e53d0230ecc89b1f5a0698fbe716903f8 Mon Sep 17 00:00:00 2001 From: Frank Pavageau Date: Thu, 19 Apr 2018 12:20:35 +0200 Subject: [PATCH] Size the lists of nodes --- .../sonar/sslr/impl/typed/SyntaxTreeCreator.java | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/sslr-core/src/main/java/com/sonar/sslr/impl/typed/SyntaxTreeCreator.java b/sslr-core/src/main/java/com/sonar/sslr/impl/typed/SyntaxTreeCreator.java index 61163a65f..ef767c0d8 100644 --- a/sslr-core/src/main/java/com/sonar/sslr/impl/typed/SyntaxTreeCreator.java +++ b/sslr-core/src/main/java/com/sonar/sslr/impl/typed/SyntaxTreeCreator.java @@ -76,28 +76,29 @@ private Object visitNonTerminal(ParseNode node) { Object result; + List children = node.getChildren(); if (mapping.hasMethodForRuleKey(ruleKey)) { // TODO Drop useless intermediate nodes - if (node.getChildren().size() != 1) { + if (children.size() != 1) { throw new IllegalStateException(); } - result = visit(node.getChildren().get(0)); + result = visit(children.get(0)); } else if (mapping.isOptionalRule(ruleKey)) { - if (node.getChildren().size() > 1) { + if (children.size() > 1) { throw new IllegalStateException(); } - if (node.getChildren().isEmpty()) { + if (children.isEmpty()) { result = Optional.absent(); } else { - result = Optional.of(visit(node.getChildren().get(0))); + result = Optional.of(visit(children.get(0))); } } else { - List convertedChildren = new ArrayList<>(); - for (ParseNode child : node.getChildren()) { + List convertedChildren = new ArrayList<>(children.size()); + for (ParseNode child : children) { convertedChildren.add(visit(child)); } if (mapping.isOneOrMoreRule(ruleKey)) {