From fb1cad3057b1f6bf68b2863d55d4967323fc9a09 Mon Sep 17 00:00:00 2001 From: David Hewitt Date: Tue, 14 Nov 2023 13:55:57 +0000 Subject: [PATCH] resolve performance regression vs main --- src/validators/tuple.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/validators/tuple.rs b/src/validators/tuple.rs index 7d41fc45c..8a1d6d68d 100644 --- a/src/validators/tuple.rs +++ b/src/validators/tuple.rs @@ -105,7 +105,11 @@ impl TupleValidator { collection_iter: &mut NextCountingIterator>, actual_length: Option, ) -> ValResult<'data, Vec> { - let expected_length = self.validators.len(); + let expected_length = if self.variadic_item_index.is_some() { + actual_length.unwrap_or(self.validators.len()) + } else { + self.validators.len() + }; let mut output = Vec::with_capacity(expected_length); if let Some(variable_validator_index) = self.variadic_item_index { let (head_validators, [variable_validator, tail_validators @ ..]) = @@ -197,7 +201,7 @@ impl TupleValidator { )?; // Generate an error if there are any extra items: - if let Some((index, _)) = collection_iter.next() { + if collection_iter.next().is_some() { return Err(ValError::new( ErrorType::TooLong { field_type: "Tuple".to_string(),