From 2e64f017f8970f144f6204b7e177a5615808beed Mon Sep 17 00:00:00 2001 From: Bas Leijdekkers Date: Sat, 7 Jul 2018 14:08:24 +0200 Subject: [PATCH] IG: fix bad performance of ExpressionUtils.isStringConcatenationOperand() --- .../siyeh/ig/psiutils/ExpressionUtils.java | 22 ++++++++----------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/psiutils/ExpressionUtils.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/psiutils/ExpressionUtils.java index 7d0cf6a798bf..f60bc11e9705 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/psiutils/ExpressionUtils.java +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/psiutils/ExpressionUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2005-2017 Bas Leijdekkers + * Copyright 2005-2018 Bas Leijdekkers * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -489,28 +489,24 @@ public class ExpressionUtils { if (!(parent instanceof PsiPolyadicExpression)) { return false; } - final PsiPolyadicExpression polyadicExpression = - (PsiPolyadicExpression)parent; - if (!JavaTokenType.PLUS.equals( - polyadicExpression.getOperationTokenType())) { + final PsiPolyadicExpression polyadicExpression = (PsiPolyadicExpression)parent; + if (!JavaTokenType.PLUS.equals(polyadicExpression.getOperationTokenType())) { return false; } final PsiExpression[] operands = polyadicExpression.getOperands(); if (operands.length < 2) { return false; } - final int index = ArrayUtil.indexOf(operands, expression, (operand, e) -> - operand == e || PsiTreeUtil.isAncestor(operand, e, false)); - for (int i = 0; i < index; i++) { - final PsiType type = operands[i].getType(); + for (int i = 0; i < operands.length; i++) { + final PsiExpression operand = operands[i]; + if (operand == expression || PsiTreeUtil.isAncestor(operand, expression, false)) { + return i == 0 && TypeUtils.isJavaLangString(operands[1].getType()); + } + final PsiType type = operand.getType(); if (TypeUtils.isJavaLangString(type)) { return true; } } - if (index == 0) { - final PsiType type = operands[index + 1].getType(); - return TypeUtils.isJavaLangString(type); - } return false; }