From: Ben Pfaff Date: Sat, 3 Jan 2026 22:39:18 +0000 (-0800) Subject: cleanup X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3b2b00f27e44f0e3ab9aa8f9f60c1dfc8bdf7378;p=pspp cleanup --- diff --git a/rust/pspp/src/spv/read/legacy_xml.rs b/rust/pspp/src/spv/read/legacy_xml.rs index 2610c0e0f4..4856bd9623 100644 --- a/rust/pspp/src/spv/read/legacy_xml.rs +++ b/rust/pspp/src/spv/read/legacy_xml.rs @@ -244,30 +244,25 @@ impl Visualization { data: IndexMap>>>, warn: &mut dyn FnMut(LegacyXmlWarning), ) -> BTreeMap<&str, Series> { - let mut source_variables = Vec::new(); - let mut derived_variables = Vec::new(); + let mut variables: Vec<&dyn Variable> = Vec::new(); for child in &self.children { match child { - VisChild::SourceVariable(source_variable) => source_variables.push(source_variable), - VisChild::DerivedVariable(derived_variable) => { - derived_variables.push(derived_variable) - } + VisChild::SourceVariable(source_variable) => variables.push(source_variable), + VisChild::DerivedVariable(derived_variable) => variables.push(derived_variable), _ => (), } } let mut series = BTreeMap::<&str, Series>::new(); - while let n = source_variables.len() + derived_variables.len() + while let n = variables.len() && n > 0 { - source_variables.retain(|sv| !sv.decode(&data, &mut series)); - derived_variables.retain(|dv| !dv.decode(&mut series, warn)); + variables.retain(|variable| !variable.decode(&data, &mut series, warn)); - if n == source_variables.len() + derived_variables.len() { + if n == variables.len() { warn(LegacyXmlWarning::UnresolvedDependencies( - source_variables + variables .iter() - .map(|sv| sv.variable.clone()) - .chain(derived_variables.iter().map(|dv| dv.id.clone())) + .map(|variable| variable.name().into()) .collect(), )); break; @@ -823,6 +818,16 @@ impl VisChild { } } +trait Variable { + fn decode<'a>( + &'a self, + data: &IndexMap>>>, + series: &mut BTreeMap<&'a str, Series>, + warn: &mut dyn FnMut(LegacyXmlWarning), + ) -> bool; + fn name(&self) -> &str; +} + #[derive(Deserialize, Debug)] #[serde(rename_all = "camelCase")] struct SourceVariable { @@ -861,10 +866,13 @@ impl SourceVariable { &[] } } +} +impl Variable for SourceVariable { fn decode<'a>( &'a self, data: &IndexMap>>>, series: &mut BTreeMap<&'a str, Series>, + _warn: &mut dyn FnMut(LegacyXmlWarning), ) -> bool { let label_series = if let Some(label_variable) = &self.label_variable { if let Some(label_series) = series.get(label_variable.references.as_str()) { @@ -914,6 +922,9 @@ impl SourceVariable { ); true } + fn name(&self) -> &str { + &self.variable + } } #[derive(Deserialize, Debug)] @@ -931,9 +942,10 @@ struct DerivedVariable { value_map: Vec, } -impl DerivedVariable { +impl Variable for DerivedVariable { fn decode<'a>( &'a self, + _data: &IndexMap>>>, series: &mut BTreeMap<&'a str, Series>, warn: &mut dyn FnMut(LegacyXmlWarning), ) -> bool { @@ -994,6 +1006,9 @@ impl DerivedVariable { ); true } + fn name(&self) -> &str { + &self.id + } } #[derive(Deserialize, Debug)]