Skip to content

Commit 6d16a16

Browse files
committed
graphql: Avoid cloning a list
1 parent 9377729 commit 6d16a16

File tree

1 file changed

+10
-16
lines changed

1 file changed

+10
-16
lines changed

graphql/src/store/query.rs

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -388,25 +388,19 @@ fn build_child_filter_from_object(
388388
/// Parses a list of GraphQL values into a vector of entity field values.
389389
fn list_values(value: Value, filter_type: &str) -> Result<Vec<Value>, QueryExecutionError> {
390390
match value {
391-
Value::List(ref values) if !values.is_empty() => {
391+
Value::List(values) => {
392392
// Check that all values in list are of the same type
393393
let root_discriminant = discriminant(&values[0]);
394-
values
395-
.iter()
396-
.map(|value| {
397-
let current_discriminant = discriminant(value);
398-
if root_discriminant == current_discriminant {
399-
Ok(value.clone())
400-
} else {
401-
Err(QueryExecutionError::ListTypesError(
402-
filter_type.to_string(),
403-
vec![values[0].to_string(), value.to_string()],
404-
))
405-
}
406-
})
407-
.collect::<Result<Vec<_>, _>>()
394+
for value in &values {
395+
if root_discriminant != discriminant(value) {
396+
return Err(QueryExecutionError::ListTypesError(
397+
filter_type.to_string(),
398+
vec![values[0].to_string(), value.to_string()],
399+
));
400+
}
401+
}
402+
Ok(values)
408403
}
409-
Value::List(ref values) if values.is_empty() => Ok(vec![]),
410404
_ => Err(QueryExecutionError::ListFilterError(
411405
filter_type.to_string(),
412406
)),

0 commit comments

Comments
 (0)