Skip to content

Commit f905b11

Browse files
committed
minimize calls to len()
1 parent 57e7499 commit f905b11

File tree

5 files changed

+11
-5
lines changed

5 files changed

+11
-5
lines changed

src/input/iterator.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ impl<'data> IterableValidationChecks<'data> {
6363
};
6464
self.input_length += 1;
6565
self.check_max_length(self.input_length, self.length_constraints.max_input_length, input)?;
66+
self.check_max_length(
67+
self.output_length + self.errors.len(),
68+
self.length_constraints.max_length,
69+
input,
70+
)?;
6671
res
6772
}
6873

src/validators/dict.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,8 @@ where
118118
);
119119
if let Some((key, value)) = checks.filter_validation_result(result, input)? {
120120
output.set_item(key, value)?;
121+
checks.check_output_length(output.len(), input)?;
121122
}
122-
checks.check_output_length(output.len(), input)?;
123123
}
124124
checks.finish(input)?;
125125
Ok(())

src/validators/list.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,8 @@ where
192192
.map_err(|e| e.with_outer_location(index.into()));
193193
if let Some(value) = checks.filter_validation_result(result, input)? {
194194
output.push(value);
195+
checks.check_output_length(output.len(), input)?;
195196
}
196-
checks.check_output_length(output.len(), input)?;
197197
}
198198
checks.finish(input)?;
199199
Ok(())

src/validators/sets.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,8 +306,8 @@ where
306306
.map_err(|e| e.with_outer_location(index.into()));
307307
if let Some(value) = checks.filter_validation_result(result, input)? {
308308
output.add(value)?;
309+
checks.check_output_length(output.len(), input)?;
309310
}
310-
checks.check_output_length(output.len(), input)?;
311311
}
312312
checks.finish(input)?;
313313
Ok(())

src/validators/tuple.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ where
7171
.map_err(|e| e.with_outer_location(index.into()));
7272
if let Some(value) = checks.filter_validation_result(result, input)? {
7373
output.push(value);
74+
checks.check_output_length(output.len(), input)?;
7475
}
75-
checks.check_output_length(output.len(), input)?;
7676
}
7777
checks.finish(input)?;
7878
Ok(())
@@ -241,6 +241,7 @@ where
241241
.map_err(|e| e.with_outer_location(index.into()));
242242
if let Some(value) = checks.filter_validation_result(result, input)? {
243243
output.push(value);
244+
checks.check_output_length(output.len(), input)?;
244245
}
245246
}
246247
None => {
@@ -252,6 +253,7 @@ where
252253
.map_err(|e| e.with_outer_location(index.into()));
253254
if let Some(value) = checks.filter_validation_result(result, input)? {
254255
output.push(value);
256+
checks.check_output_length(output.len(), input)?;
255257
}
256258
}
257259
None => {
@@ -267,7 +269,6 @@ where
267269
}
268270
}
269271
}
270-
checks.check_output_length(output.len(), input)?;
271272
}
272273
for (idx, validator) in items_validators.iter().enumerate().skip(output.len()) {
273274
let default = validator.default_value(py, Some(output.len()), extra, definitions, recursion_guard)?;

0 commit comments

Comments
 (0)