Skip to content

Commit

Permalink
Optimize SimpleAliasRegistry hasAlias implementation
Browse files Browse the repository at this point in the history
This commit reduces the number of loops and recursions in
the implementation of SimpleAliasRegistry#hasAlias().

Closes gh-24295
  • Loading branch information
chenqimiao authored and sbrannen committed Jan 6, 2020
1 parent 328e88d commit d0c2812
Showing 1 changed file with 5 additions and 10 deletions.
Expand Up @@ -26,6 +26,7 @@
import org.apache.commons.logging.LogFactory;

import org.springframework.util.Assert;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
import org.springframework.util.StringValueResolver;

Expand All @@ -36,6 +37,7 @@
* implementations.
*
* @author Juergen Hoeller
* @author Qimiao Chen
* @since 2.5.2
*/
public class SimpleAliasRegistry implements AliasRegistry {
Expand Down Expand Up @@ -98,16 +100,9 @@ protected boolean allowAliasOverriding() {
* @since 4.2.1
*/
public boolean hasAlias(String name, String alias) {
for (Map.Entry<String, String> entry : this.aliasMap.entrySet()) {
String registeredName = entry.getValue();
if (registeredName.equals(name)) {
String registeredAlias = entry.getKey();
if (registeredAlias.equals(alias) || hasAlias(registeredAlias, alias)) {
return true;
}
}
}
return false;
String registeredName = this.aliasMap.get(alias);
return ObjectUtils.nullSafeEquals(registeredName, name) || (registeredName != null
&& hasAlias(name, registeredName));
}

@Override
Expand Down

0 comments on commit d0c2812

Please sign in to comment.