[Codenarc-developer] GMetrics ASTUtils needs to change
Brought to you by:
chrismair
From: Hamlet D. <ham...@ca...> - 2011-09-15 07:17:14
|
Hi Chris, One of the bigger bottlenecks in CodeNarc is now the GMetrics#ASTUtil getVariableExpressions class. If you could change it to be implemented *exactly* the same way as CodeNarc, then we would shave about 8-10% off the total times. Here is how the method should be implemented: static List getVariableExpressions(DeclarationExpression declarationExpression) { def leftExpression = declarationExpression.leftExpression // !important: performance enhancement if (leftExpression instanceof ArrayExpression) { leftExpression.expressions ?: [leftExpression] } else if (leftExpression instanceof ListExpression) { leftExpression.expressions ?: [leftExpression] } else if (leftExpression instanceof TupleExpression) { leftExpression.expressions ?: [leftExpression] } else if (leftExpression instanceof VariableExpression) { [leftExpression] } else { leftExpression.properties['expressions'] ?: [leftExpression] } } Basically, the last else block should *never* be called. If we ever find that it is called then we need to add a new if branch to avoid that. Hmmm... perhaps we should add a LOG.warning there? -- Hamlet D'Arcy ham...@ca... |