Skip to content

Commit 050f8cf

Browse files
committed
Fix #896: performance improvement on Beans#isProxy and inherently also
Beans#unwrapIfNecessary() and o:validateBean and @param
1 parent 27a013e commit 050f8cf

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

src/main/java/org/omnifaces/util/Beans.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,16 @@
1414

1515
import static java.util.logging.Level.FINE;
1616
import static java.util.regex.Pattern.CASE_INSENSITIVE;
17+
import static java.util.stream.Collectors.toList;
1718
import static org.omnifaces.util.Reflection.toClassOrNull;
1819

1920
import java.lang.annotation.Annotation;
21+
import java.util.List;
2022
import java.util.Map;
23+
import java.util.Objects;
2124
import java.util.logging.Logger;
2225
import java.util.regex.Pattern;
26+
import java.util.stream.Stream;
2327

2428
import javax.enterprise.context.ContextNotActiveException;
2529
import javax.enterprise.context.spi.AlterableContext;
@@ -77,12 +81,12 @@ public final class Beans {
7781

7882
private static final Logger logger = Logger.getLogger(Beans.class.getName());
7983

80-
private static final String[] PROXY_INTERFACE_NAMES = {
81-
"org.jboss.weld.proxy.WeldConstruct",
82-
"org.apache.webbeans.proxy.OwbNormalScopeProxy",
83-
"io.quarkus.arc.ClientProxy",
84-
"io.quarkus.arc.Subclass"
85-
};
84+
private static final List<Class<?>> PROXY_INTERFACES = Stream.of(
85+
toClassOrNull("org.jboss.weld.proxy.WeldConstruct"),
86+
toClassOrNull("org.apache.webbeans.proxy.OwbNormalScopeProxy"),
87+
toClassOrNull("io.quarkus.arc.ClientProxy"),
88+
toClassOrNull("io.quarkus.arc.Subclass")
89+
).filter(Objects::nonNull).collect(toList());
8690

8791
// Both Weld and OWB generate proxy class names as "BeanClassName[...]$$[...]Proxy[...]" with a "$$" and "Proxy" in it.
8892
// Hopefully unknown CDI proxy implementations follow the same de-facto standard.
@@ -275,14 +279,10 @@ public static <T> boolean isProxy(T object) {
275279
return false;
276280
}
277281

278-
Class<?> beanClass = (object instanceof Class) ? (Class<?>) object : object.getClass();
282+
Class<?> beanClass = object instanceof Class ? (Class<?>) object : object.getClass();
279283

280-
for (String proxyInterfaceName : PROXY_INTERFACE_NAMES) {
281-
Class<?> proxyInterface = toClassOrNull(proxyInterfaceName);
282-
283-
if (proxyInterface != null && proxyInterface.isAssignableFrom(beanClass)) {
284-
return true;
285-
}
284+
if (PROXY_INTERFACES.stream().anyMatch(proxyInterface -> proxyInterface.isAssignableFrom(beanClass))) {
285+
return true;
286286
}
287287

288288
// Fall back for unknown CDI proxy implementations.

0 commit comments

Comments
 (0)