Skip to content

Commit

Permalink
Abort type determination for List early (#9779)
Browse files Browse the repository at this point in the history
# Description
If we reach the conclusion that the fields of a list are of `Type::Any`
there is no need to continue as the type will remain `Type::Any`

This should improve runtimes of `Value.get_type()` for lists with mixed
types.

# User-Facing Changes
None, a speedup in some cases.

# Tests + Formatting
Relies on existing tests
  • Loading branch information
sholderbach committed Jul 24, 2023
1 parent 2aeb77b commit 2dcd1c5
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions crates/nu-protocol/src/value/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,8 @@ impl Value {
if x.is_numeric() && val_ty.is_numeric() {
ty = Some(Type::Number)
} else {
ty = Some(Type::Any)
ty = Some(Type::Any);
break;
}
}
}
Expand All @@ -574,7 +575,7 @@ impl Value {
match ty {
Some(Type::Record(columns)) => Type::Table(columns),
Some(ty) => Type::List(Box::new(ty)),
None => Type::List(Box::new(ty.unwrap_or(Type::Any))),
None => Type::List(Box::new(Type::Any)),
}
}
Value::LazyRecord { val, .. } => match val.collect() {
Expand Down

0 comments on commit 2dcd1c5

Please sign in to comment.