Skip to content

Commit

Permalink
Revert boxing of Record (nushell#12252)
Browse files Browse the repository at this point in the history
  • Loading branch information
sholderbach committed Mar 28, 2024
1 parent 215e168 commit d38c4c5
Show file tree
Hide file tree
Showing 34 changed files with 54 additions and 56 deletions.
2 changes: 1 addition & 1 deletion crates/nu-cli/src/completions/variable_completions.rs
Expand Up @@ -317,7 +317,7 @@ fn recursive_value(val: Value, sublevels: Vec<Vec<u8>>) -> Value {
let span = val.span();
match val {
Value::Record { val, .. } => {
for item in *val {
for item in val {
// Check if index matches with sublevel
if item.0.as_bytes().to_vec() == next_sublevel {
// If matches try to fetch recursively the next
Expand Down
2 changes: 1 addition & 1 deletion crates/nu-cmd-base/src/hook.rs
Expand Up @@ -18,7 +18,7 @@ pub fn eval_env_change_hook(
if let Some(hook) = env_change_hook {
match hook {
Value::Record { val, .. } => {
for (env_name, hook_value) in &*val {
for (env_name, hook_value) in &val {
let before = engine_state
.previous_env_vars
.get(env_name)
Expand Down
Expand Up @@ -163,7 +163,7 @@ impl NuDataFrame {
conversion::insert_record(&mut column_values, record, &maybe_schema)?
}
Value::Record { val: record, .. } => {
conversion::insert_record(&mut column_values, *record, &maybe_schema)?
conversion::insert_record(&mut column_values, record, &maybe_schema)?
}
_ => {
let key = "0".to_string();
Expand Down
4 changes: 2 additions & 2 deletions crates/nu-cmd-lang/src/core_commands/describe.rs
Expand Up @@ -317,7 +317,7 @@ fn describe_value(
record!(
"type" => Value::string("record", head),
"lazy" => Value::bool(false, head),
"columns" => Value::record(*val, head),
"columns" => Value::record(val, head),
),
head,
)
Expand Down Expand Up @@ -408,7 +408,7 @@ fn describe_value(
)?);
}

record.push("columns", Value::record(*val, head));
record.push("columns", Value::record(val, head));
} else {
let cols = val.column_names();
record.push("length", Value::int(cols.len() as i64, head));
Expand Down
2 changes: 1 addition & 1 deletion crates/nu-cmd-lang/src/example_support.rs
Expand Up @@ -237,7 +237,7 @@ impl<'a> std::fmt::Debug for DebuggableValue<'a> {
Value::Record { val, .. } => {
write!(f, "{{")?;
let mut first = true;
for (col, value) in (&**val).into_iter() {
for (col, value) in val.into_iter() {
if !first {
write!(f, ", ")?;
}
Expand Down
2 changes: 1 addition & 1 deletion crates/nu-command/src/charting/histogram.rs
Expand Up @@ -177,7 +177,7 @@ fn run_histogram(
match v {
// parse record, and fill valid value to actual input.
Value::Record { val, .. } => {
for (c, v) in *val {
for (c, v) in val {
if &c == col_name {
if let Ok(v) = HashableValue::from_value(v, head_span) {
inputs.push(v);
Expand Down
2 changes: 1 addition & 1 deletion crates/nu-command/src/conversions/into/record.rs
Expand Up @@ -131,7 +131,7 @@ fn into_record(
.collect(),
span,
),
Value::Record { val, .. } => Value::record(*val, span),
Value::Record { val, .. } => Value::record(val, span),
Value::Error { .. } => input,
other => Value::error(
ShellError::TypeMismatch {
Expand Down
2 changes: 1 addition & 1 deletion crates/nu-command/src/env/load_env.rs
Expand Up @@ -53,7 +53,7 @@ impl Command for LoadEnv {
}
None => match input {
PipelineData::Value(Value::Record { val, .. }, ..) => {
for (env_var, rhs) in *val {
for (env_var, rhs) in val {
let env_var_ = env_var.as_str();
if ["FILE_PWD", "CURRENT_FILE"].contains(&env_var_) {
return Err(ShellError::AutomaticEnvVarSetManually {
Expand Down
4 changes: 2 additions & 2 deletions crates/nu-command/src/env/with_env.rs
Expand Up @@ -89,7 +89,7 @@ fn with_env(
// single row([[X W]; [Y Z]])
match &table[0] {
Value::Record { val, .. } => {
for (k, v) in &**val {
for (k, v) in val {
env.insert(k.to_string(), v.clone());
}
}
Expand Down Expand Up @@ -117,7 +117,7 @@ fn with_env(
}
// when get object by `open x.json` or `from json`
Value::Record { val, .. } => {
for (k, v) in &**val {
for (k, v) in val {
env.insert(k.clone(), v.clone());
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/nu-command/src/filters/default.rs
Expand Up @@ -106,7 +106,7 @@ fn default(
record.push(column.item.clone(), value.clone());
}

Value::record(*record, span)
Value::record(record, span)
}
_ => item,
}
Expand Down
2 changes: 1 addition & 1 deletion crates/nu-command/src/filters/drop/column.rs
Expand Up @@ -123,7 +123,7 @@ fn drop_cols(
} => {
let len = record.len().saturating_sub(columns);
record.truncate(len);
Ok(Value::record(*record, span).into_pipeline_data_with_metadata(metadata))
Ok(Value::record(record, span).into_pipeline_data_with_metadata(metadata))
}
// Propagate errors
Value::Error { error, .. } => Err(*error),
Expand Down
6 changes: 3 additions & 3 deletions crates/nu-command/src/filters/flatten.rs
Expand Up @@ -164,17 +164,17 @@ fn flat_value(columns: &[CellPath], item: Value, all: bool) -> Vec<Value> {
match value {
Value::Record { val, .. } => {
if need_flatten {
for (col, val) in *val {
for (col, val) in val {
if out.contains_key(&col) {
out.insert(format!("{column}_{col}"), val);
} else {
out.insert(col, val);
}
}
} else if out.contains_key(&column) {
out.insert(format!("{column}_{column}"), Value::record(*val, span));
out.insert(format!("{column}_{column}"), Value::record(val, span));
} else {
out.insert(column, Value::record(*val, span));
out.insert(column, Value::record(val, span));
}
}
Value::List { vals, .. } => {
Expand Down
2 changes: 1 addition & 1 deletion crates/nu-command/src/filters/sort.rs
Expand Up @@ -144,7 +144,7 @@ impl Command for Sort {
// Records have two sorting methods, toggled by presence or absence of -v
PipelineData::Value(Value::Record { val, .. }, ..) => {
let sort_by_value = call.has_flag(engine_state, stack, "values")?;
let record = sort_record(*val, span, sort_by_value, reverse, insensitive, natural);
let record = sort_record(val, span, sort_by_value, reverse, insensitive, natural);
Ok(record.into_pipeline_data())
}
// Other values are sorted here
Expand Down
2 changes: 1 addition & 1 deletion crates/nu-command/src/filters/values.rs
Expand Up @@ -106,7 +106,7 @@ pub fn get_values<'a>(
for item in input {
match item {
Value::Record { val, .. } => {
for (k, v) in &**val {
for (k, v) in val {
if let Some(vec) = output.get_mut(k) {
vec.push(v.clone());
} else {
Expand Down
2 changes: 1 addition & 1 deletion crates/nu-command/src/formats/from/xml.rs
Expand Up @@ -412,7 +412,7 @@ mod tests {
content_tag(
"nu",
indexmap! {},
&[
&vec![
content_tag("dev", indexmap! {}, &[content_string("Andrés")]),
content_tag("dev", indexmap! {}, &[content_string("JT")]),
content_tag("dev", indexmap! {}, &[content_string("Yehuda")])
Expand Down
2 changes: 1 addition & 1 deletion crates/nu-command/src/formats/to/json.rs
Expand Up @@ -130,7 +130,7 @@ pub fn value_to_json_value(v: &Value) -> Result<nu_json::Value, ShellError> {
}
Value::Record { val, .. } => {
let mut m = nu_json::Map::new();
for (k, v) in &**val {
for (k, v) in val {
m.insert(k.clone(), value_to_json_value(v)?);
}
nu_json::Value::Object(m)
Expand Down
2 changes: 1 addition & 1 deletion crates/nu-command/src/formats/to/nuon.rs
Expand Up @@ -246,7 +246,7 @@ pub fn value_to_string(
)),
Value::Record { val, .. } => {
let mut collection = vec![];
for (col, val) in &**val {
for (col, val) in val {
collection.push(if needs_quotes(col) {
format!(
"{idt_po}\"{}\": {}",
Expand Down
2 changes: 1 addition & 1 deletion crates/nu-command/src/formats/to/toml.rs
Expand Up @@ -57,7 +57,7 @@ fn helper(engine_state: &EngineState, v: &Value) -> Result<toml::Value, ShellErr
Value::String { val, .. } | Value::Glob { val, .. } => toml::Value::String(val.clone()),
Value::Record { val, .. } => {
let mut m = toml::map::Map::new();
for (k, v) in &**val {
for (k, v) in val {
m.insert(k.clone(), helper(engine_state, v)?);
}
toml::Value::Table(m)
Expand Down
4 changes: 2 additions & 2 deletions crates/nu-command/src/formats/to/xml.rs
Expand Up @@ -326,7 +326,7 @@ impl Job {
// content: null}, {tag: a}. See to_xml_entry for more
let attrs = match attrs {
Value::Record { val, .. } => val,
Value::Nothing { .. } => Box::new(Record::new()),
Value::Nothing { .. } => Record::new(),
_ => {
return Err(ShellError::CantConvert {
to_type: "XML".into(),
Expand All @@ -350,7 +350,7 @@ impl Job {
}
};

self.write_tag(entry_span, tag, tag_span, *attrs, content)
self.write_tag(entry_span, tag, tag_span, attrs, content)
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/nu-command/src/formats/to/yaml.rs
Expand Up @@ -54,7 +54,7 @@ pub fn value_to_yaml_value(v: &Value) -> Result<serde_yaml::Value, ShellError> {
}
Value::Record { val, .. } => {
let mut m = serde_yaml::Mapping::new();
for (k, v) in &**val {
for (k, v) in val {
m.insert(
serde_yaml::Value::String(k.clone()),
value_to_yaml_value(v)?,
Expand Down
2 changes: 1 addition & 1 deletion crates/nu-command/src/help/help_.rs
Expand Up @@ -180,7 +180,7 @@ pub fn highlight_search_in_table(
)?;

if has_match {
matches.push(Value::record(*record, record_span));
matches.push(Value::record(record, record_span));
}
}

Expand Down
4 changes: 2 additions & 2 deletions crates/nu-command/src/math/utils.rs
Expand Up @@ -27,7 +27,7 @@ fn helper_for_tables(
for val in values {
match val {
Value::Record { val, .. } => {
for (key, value) in &**val {
for (key, value) in val {
column_values
.entry(key.clone())
.and_modify(|v: &mut Vec<Value>| v.push(value.clone()))
Expand Down Expand Up @@ -88,7 +88,7 @@ pub fn calculate(
*val = mf(slice::from_ref(val), span, name)?;
Ok(())
})?;
Ok(Value::record(*record, span))
Ok(Value::record(record, span))
}
PipelineData::Value(Value::Range { val, .. }, ..) => {
let new_vals: Result<Vec<Value>, ShellError> = val
Expand Down
6 changes: 3 additions & 3 deletions crates/nu-command/src/network/http/client.rs
Expand Up @@ -222,7 +222,7 @@ pub fn send_request(
Value::Record { val, .. } if body_type == BodyType::Form => {
let mut data: Vec<(String, String)> = Vec::with_capacity(val.len());

for (col, val) in *val {
for (col, val) in val {
data.push((col, val.coerce_into_string()?))
}

Expand Down Expand Up @@ -336,7 +336,7 @@ pub fn request_add_custom_headers(

match &headers {
Value::Record { val, .. } => {
for (k, v) in &**val {
for (k, v) in val {
custom_headers.insert(k.to_string(), v.clone());
}
}
Expand All @@ -346,7 +346,7 @@ pub fn request_add_custom_headers(
// single row([key1 key2]; [val1 val2])
match &table[0] {
Value::Record { val, .. } => {
for (k, v) in &**val {
for (k, v) in val {
custom_headers.insert(k.to_string(), v.clone());
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/nu-command/src/network/url/build_query.rs
Expand Up @@ -65,7 +65,7 @@ fn to_url(input: PipelineData, head: Span) -> Result<PipelineData, ShellError> {
match value {
Value::Record { ref val, .. } => {
let mut row_vec = vec![];
for (k, v) in &**val {
for (k, v) in val {
match v.coerce_string() {
Ok(s) => {
row_vec.push((k.clone(), s));
Expand Down
2 changes: 1 addition & 1 deletion crates/nu-command/src/viewers/table.rs
Expand Up @@ -392,7 +392,7 @@ fn handle_table_command(
}
PipelineData::Value(Value::Record { val, .. }, ..) => {
input.data = PipelineData::Empty;
handle_record(input, cfg, *val)
handle_record(input, cfg, val)
}
PipelineData::Value(Value::LazyRecord { val, .. }, ..) => {
input.data = val.collect()?.into_pipeline_data();
Expand Down
4 changes: 2 additions & 2 deletions crates/nu-engine/src/documentation.rs
Expand Up @@ -376,8 +376,8 @@ fn get_argument_for_color_value(
) -> Option<Argument> {
match color {
Value::Record { val, .. } => {
let record_exp: Vec<RecordItem> = (**val)
.iter()
let record_exp: Vec<RecordItem> = val
.into_iter()
.map(|(k, v)| {
RecordItem::Pair(
Expression {
Expand Down
2 changes: 1 addition & 1 deletion crates/nu-explore/src/nu_common/table.rs
Expand Up @@ -16,7 +16,7 @@ pub fn try_build_table(
let span = value.span();
match value {
Value::List { vals, .. } => try_build_list(vals, ctrlc, config, span, style_computer),
Value::Record { val, .. } => try_build_map(*val, span, style_computer, ctrlc, config),
Value::Record { val, .. } => try_build_map(val, span, style_computer, ctrlc, config),
val if matches!(val, Value::String { .. }) => {
nu_value_to_string_clean(&val, config, style_computer).0
}
Expand Down
2 changes: 1 addition & 1 deletion crates/nu-protocol/src/config/hooks.rs
Expand Up @@ -39,7 +39,7 @@ pub(super) fn create_hooks(value: &Value) -> Result<Hooks, ShellError> {
Value::Record { val, .. } => {
let mut hooks = Hooks::new();

for (col, val) in &**val {
for (col, val) in val {
match col.as_str() {
"pre_prompt" => hooks.pre_prompt = Some(val.clone()),
"pre_execution" => hooks.pre_execution = Some(val.clone()),
Expand Down
2 changes: 1 addition & 1 deletion crates/nu-protocol/src/engine/pattern_match.rs
Expand Up @@ -23,7 +23,7 @@ impl Matcher for Pattern {
Pattern::Record(field_patterns) => match value {
Value::Record { val, .. } => {
'top: for field_pattern in field_patterns {
for (col, val) in &**val {
for (col, val) in val {
if col == &field_pattern.0 {
// We have found the field
let result = field_pattern.1.match_value(val, matches);
Expand Down
2 changes: 1 addition & 1 deletion crates/nu-protocol/src/eval_base.rs
Expand Up @@ -75,7 +75,7 @@ pub trait Eval {
RecordItem::Spread(_, inner) => {
match Self::eval::<D>(state, mut_state, inner)? {
Value::Record { val: inner_val, .. } => {
for (col_name, val) in *inner_val {
for (col_name, val) in inner_val {
if let Some(orig_span) = col_names.get(&col_name) {
return Err(ShellError::ColumnDefinedTwice {
col_name,
Expand Down
2 changes: 1 addition & 1 deletion crates/nu-protocol/src/value/from_value.rs
Expand Up @@ -538,7 +538,7 @@ impl FromValue for Vec<Value> {
impl FromValue for Record {
fn from_value(v: Value) -> Result<Self, ShellError> {
match v {
Value::Record { val, .. } => Ok(*val),
Value::Record { val, .. } => Ok(val),
v => Err(ShellError::CantConvert {
to_type: "Record".into(),
from_type: v.get_type().to_string(),
Expand Down
6 changes: 3 additions & 3 deletions crates/nu-protocol/src/value/mod.rs
Expand Up @@ -109,7 +109,7 @@ pub enum Value {
internal_span: Span,
},
Record {
val: Box<Record>,
val: Record,
// note: spans are being refactored out of Value
// please use .span() instead of matching this span value
#[serde(rename = "span")]
Expand Down Expand Up @@ -537,7 +537,7 @@ impl Value {
/// Unwraps the inner [`Record`] value or returns an error if this `Value` is not a record
pub fn into_record(self) -> Result<Record, ShellError> {
if let Value::Record { val, .. } = self {
Ok(*val)
Ok(val)
} else {
self.cant_convert_to("record")
}
Expand Down Expand Up @@ -1997,7 +1997,7 @@ impl Value {

pub fn record(val: Record, span: Span) -> Value {
Value::Record {
val: Box::new(val),
val,
internal_span: span,
}
}
Expand Down

0 comments on commit d38c4c5

Please sign in to comment.