You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@bval.apache.org by ta...@apache.org on 2026/07/24 23:32:27 UTC

(bval) 09/09: Visit unwrapped frames via a consumer instead of a Stream per constraint (avoids Stream.of(this) on the common no-unwrapping path)

This is an automated email from the ASF dual-hosted git repository.

asf-gitbox-commits pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/bval.git

commit 7917434c4ba33ef6c57f12166cc05735dd784e7f
Author: tandraschko <ta...@apache.org>
AuthorDate: Sat Jul 25 01:13:57 2026 +0200

    Visit unwrapped frames via a consumer instead of a Stream per constraint (avoids Stream.of(this) on the common no-unwrapping path)
---
 .../org/apache/bval/jsr/job/ValidationJob.java     | 25 ++++++++++++----------
 1 file changed, 14 insertions(+), 11 deletions(-)

diff --git a/bval-jsr/src/main/java/org/apache/bval/jsr/job/ValidationJob.java b/bval-jsr/src/main/java/org/apache/bval/jsr/job/ValidationJob.java
index 4da1f30..e57cc22 100644
--- a/bval-jsr/src/main/java/org/apache/bval/jsr/job/ValidationJob.java
+++ b/bval-jsr/src/main/java/org/apache/bval/jsr/job/ValidationJob.java
@@ -119,24 +119,27 @@ public abstract class ValidationJob<T> {
         abstract Object getBean();
 
         void validateDescriptorConstraints(GroupStrategy groups, Consumer<ConstraintViolation<T>> sink) {
-            constraintsFor(descriptor, groups)
-                    .forEach(c -> unwrap(c.getValueUnwrapping()).forEach(f -> f.validate(c, sink)));
+            constraintsFor(descriptor, groups).forEach(c -> validateUnwrapped(c, sink));
         }
 
-        private Stream<Frame<D>> unwrap(ValidateUnwrappedValue valueUnwrapping) {
+        // Visit each (possibly unwrapped) frame for this constraint without allocating a Stream per constraint;
+        // the common case is no unwrapping, i.e. a direct validate(this).
+        private void validateUnwrapped(ConstraintD<?> constraint, Consumer<ConstraintViolation<T>> sink) {
+            final ValidateUnwrappedValue valueUnwrapping = constraint.getValueUnwrapping();
             if (valueUnwrapping != ValidateUnwrappedValue.SKIP && context.getValue() != null) {
-                final Optional<ValueExtractors.UnwrappingInfo> valueExtractorAndAssociatedContainerElementKey =
+                final Optional<ValueExtractors.UnwrappingInfo> unwrappingInfo =
                         validatorContext.getValueExtractors().findUnwrappingInfo(context.getValue().getClass(),
                                 valueUnwrapping);
-
-                if (valueExtractorAndAssociatedContainerElementKey.isPresent()) {
-                    return ExtractValues
-                            .extract(context, valueExtractorAndAssociatedContainerElementKey.get().containerElementKey,
-                                    valueExtractorAndAssociatedContainerElementKey.get().valueExtractor)
-                            .stream().map(child -> new UnwrappedElementConstraintValidationPseudoFrame<>(this, child));
+                if (unwrappingInfo.isPresent()) {
+                    for (final GraphContext child : ExtractValues.extract(context,
+                            unwrappingInfo.get().containerElementKey, unwrappingInfo.get().valueExtractor)) {
+                        final Frame<D> frame = new UnwrappedElementConstraintValidationPseudoFrame<>(this, child);
+                        frame.validate(constraint, sink);
+                    }
+                    return;
                 }
             }
-            return Stream.of(this);
+            validate(constraint, sink);
         }
 
         @SuppressWarnings({ "rawtypes", "unchecked" })