From 801f196de05a2d8424c30a66bede6f9a5bfa713d Mon Sep 17 00:00:00 2001 From: David Harkness Date: Tue, 12 Mar 2013 20:38:03 -0700 Subject: [PATCH] Compare Kind references before checking log levels Assuming reference comparisons are much quicker than checking likely-nested logger levels, perform the former first. Also, since the reference can match only one of the instances, use "else if" to short-circuit the search. --- .../aspectj/AspectJWeaverMessageHandler.java | 26 ++++++++----------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJWeaverMessageHandler.java b/spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJWeaverMessageHandler.java index 4505e6f330..678c87baeb 100644 --- a/spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJWeaverMessageHandler.java +++ b/spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJWeaverMessageHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2013 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -51,36 +51,32 @@ public class AspectJWeaverMessageHandler implements IMessageHandler { public boolean handleMessage(IMessage message) throws AbortException { Kind messageKind = message.getKind(); - if (LOGGER.isDebugEnabled() || LOGGER.isTraceEnabled()) { - if (messageKind == IMessage.DEBUG) { + if (messageKind == IMessage.DEBUG) { + if (LOGGER.isDebugEnabled() || LOGGER.isTraceEnabled()) { LOGGER.debug(makeMessageFor(message)); return true; } } - - if (LOGGER.isInfoEnabled()) { - if ((messageKind == IMessage.INFO) || (messageKind == IMessage.WEAVEINFO)) { + else if ((messageKind == IMessage.INFO) || (messageKind == IMessage.WEAVEINFO)) { + if (LOGGER.isInfoEnabled()) { LOGGER.info(makeMessageFor(message)); return true; } } - - if (LOGGER.isWarnEnabled()) { - if (messageKind == IMessage.WARNING) { + else if (messageKind == IMessage.WARNING) { + if (LOGGER.isWarnEnabled()) { LOGGER.warn(makeMessageFor(message)); return true; } } - - if (LOGGER.isErrorEnabled()) { - if (messageKind == IMessage.ERROR) { + else if (messageKind == IMessage.ERROR) { + if (LOGGER.isErrorEnabled()) { LOGGER.error(makeMessageFor(message)); return true; } } - - if (LOGGER.isFatalEnabled()) { - if (messageKind == IMessage.ABORT) { + else if (messageKind == IMessage.ABORT) { + if (LOGGER.isFatalEnabled()) { LOGGER.fatal(makeMessageFor(message)); return true; }