Skip to content

Commit

Permalink
Avoid creating unnecessary CreationalContext instances for non-depend…
Browse files Browse the repository at this point in the history
…ent beans
  • Loading branch information
manovotn committed Aug 4, 2023
1 parent 800fea3 commit ecb8d45
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions impl/src/main/java/org/jboss/weld/manager/BeanManagerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -663,18 +663,17 @@ private Context internalGetContext(Class<? extends Annotation> scopeType) {
}

public Object getReference(Bean<?> bean, Type requestedType, CreationalContext<?> creationalContext, boolean noProxy) {
if (creationalContext instanceof CreationalContextImpl<?>) {
if (creationalContext == null) {
// null CC indicates we need to create a new one that has no parent linked to it
creationalContext = createCreationalContext(null);
} else if (creationalContext instanceof CreationalContextImpl<?>) {
creationalContext = ((CreationalContextImpl<?>) creationalContext).getCreationalContext(bean);
}
if (!noProxy && isProxyRequired(bean)) {
if (creationalContext != null || ContextualInstance.getIfExists(bean, this) != null) {
if (requestedType == null) {
return clientProxyProvider.getClientProxy(bean);
} else {
return clientProxyProvider.getClientProxy(bean, requestedType);
}
if (requestedType == null) {
return clientProxyProvider.getClientProxy(bean);
} else {
return null;
return clientProxyProvider.getClientProxy(bean, requestedType);
}
} else {
return ContextualInstance.get(bean, this, creationalContext);
Expand Down Expand Up @@ -782,7 +781,7 @@ public Object getInjectableReference(InjectionPoint injectionPoint, Bean<?> reso
if (Dependent.class.equals(resolvedBean.getScope())) {
return getReference(resolvedBean, requestedType, creationalContext, delegateInjectionPoint);
} else {
return getReference(resolvedBean, requestedType, createCreationalContext(null), delegateInjectionPoint);
return getReference(resolvedBean, requestedType, null, delegateInjectionPoint);
}

} finally {
Expand Down

0 comments on commit ecb8d45

Please sign in to comment.