From 6e8008ac15db4c6e451d2bdbab4234c6129ab70f Mon Sep 17 00:00:00 2001 From: AgentJill Date: Sat, 25 Jul 2026 23:38:45 +0530 Subject: [PATCH 1/3] removed unnecessary collect to improve the memory utilisation. --- src/helper/number_format.rs | 21 ++-- src/helper/number_format/date_formater.rs | 2 +- src/helper/number_format/number_formater.rs | 36 +++--- src/structs/chart.rs | 90 +++++++-------- src/structs/data_bar.rs | 12 +- src/structs/defined_name.rs | 16 +-- src/structs/drawing/charts/plot_area.rs | 119 +++++--------------- src/structs/raw/raw_file.rs | 2 +- src/structs/raw/raw_relationships.rs | 2 +- src/structs/vml/spreadsheet/anchor.rs | 22 ++-- src/structs/worksheet.rs | 2 +- 11 files changed, 127 insertions(+), 197 deletions(-) diff --git a/src/helper/number_format.rs b/src/helper/number_format.rs index f7424a10..7b5cede7 100644 --- a/src/helper/number_format.rs +++ b/src/helper/number_format.rs @@ -161,13 +161,10 @@ fn split_format(sections: Vec<&str>, value: f64) -> (String, String, String) { // Process color matching if let Some(captures) = color_re.captures(section).ok().flatten() { - let items: Vec<&str> = captures - .iter() - .filter_map(|cap| cap.map(|c| c.as_str())) - .collect(); + let mut items = captures.iter().filter_map(|cap| cap.map(|c| c.as_str())); - if let Some(first_item) = items.first() { - colors[idx].clone_from(first_item); + if let Some(first_item) = items.next() { + colors[idx].clone_from(&first_item); } converted_section = color_re.replace_all(section, "").to_string(); @@ -175,16 +172,16 @@ fn split_format(sections: Vec<&str>, value: f64) -> (String, String, String) { // Process conditional matching if let Some(captures) = cond_re.captures(section).ok().flatten() { - let items: Vec<&str> = captures + let mut items = captures .iter() .filter_map(|cap| cap.map(|c| c.as_str())) - .collect(); + .skip(1); - if let Some(v) = items.get(1) { - condops[idx].clone_from(v); + if let Some(v) = items.next() { + condops[idx].clone_from(&v); } - if let Some(v) = items.get(2) { - condvals[idx].clone_from(v); + if let Some(v) = items.next() { + condvals[idx].clone_from(&v); } converted_section = cond_re.replace_all(section, "").to_string(); diff --git a/src/helper/number_format/date_formater.rs b/src/helper/number_format/date_formater.rs index 647120f5..b2dabcf9 100644 --- a/src/helper/number_format/date_formater.rs +++ b/src/helper/number_format/date_formater.rs @@ -75,7 +75,7 @@ pub(crate) fn format_as_date(value: f64, format: &str) -> Cow<'_, str> { }); // Only process the non-quoted blocks for date format characters - let blocks: Vec<&str> = format.split('"').collect(); + let blocks = format.split('"'); let mut converted_blocks: Vec = Vec::new(); let mut i = 0; for block in blocks { diff --git a/src/helper/number_format/number_formater.rs b/src/helper/number_format/number_formater.rs index 2759e5a8..29e20c25 100644 --- a/src/helper/number_format/number_formater.rs +++ b/src/helper/number_format/number_formater.rs @@ -78,15 +78,18 @@ pub(crate) fn format_as_number(value: f64, format: &str) -> Cow<'_, str> { if !attached_affixes { let re = compile_regex!(r"\$[^0-9]*"); if re.find(&format).ok().flatten().is_some() { - let item: Vec<&str> = re - .captures(&format) - .ok() - .flatten() - .unwrap() - .iter() - .map(|ite| ite.unwrap().as_str()) - .collect(); - value = format!("{}{}", item.first().unwrap(), value); + value = format!( + "{}{}", + re.captures(&format) + .ok() + .flatten() + .unwrap() + .iter() + .map(|ite| ite.unwrap().as_str()) + .next() + .unwrap(), + value + ); } } @@ -222,7 +225,7 @@ pub(crate) fn group_thousands(value: &str) -> String { } #[allow(dead_code)] -fn merge_complex_number_format_masks(numbers: &[String], masks: &[String]) -> Vec { +fn merge_complex_number_format_masks(numbers: &[&str], masks: &[String]) -> Vec { let mut decimal_count = numbers[1].len(); let mut post_decimal_masks: Vec<&str> = Vec::new(); @@ -287,16 +290,8 @@ fn complex_number_format_mask(number: f64, mask: &str, split_on_point: bool) -> if split_on_point && mask.contains('.') && number.to_string().contains('.') { let number_str = number.to_string(); - let numbers_as: Vec<&str> = number_str.split('.').collect(); - let mut numbers: Vec = Vec::new(); - for n in numbers_as { - numbers.push(n.to_string()); - } - let masks_as: Vec<&str> = mask.split('.').collect(); - let mut masks: Vec = Vec::new(); - for mask in masks_as { - masks.push(mask.to_string()); - } + let numbers: Vec<&str> = number_str.split('.').collect(); + let mut masks: Vec = mask.split('.').map(String::from).collect(); if masks.len() > 2 { masks = merge_complex_number_format_masks(&numbers, &masks); } @@ -344,6 +339,7 @@ mod tests { #[test] fn format_as_number_wraps_parenthesized_sections() { assert_eq!(format_as_number(1234.0, "(#,##0)"), "(1,234)"); + } #[test] fn format_as_number_rounds_half_away_from_zero() { diff --git a/src/structs/chart.rs b/src/structs/chart.rs index f33901a8..210d5411 100644 --- a/src/structs/chart.rs +++ b/src/structs/chart.rs @@ -339,43 +339,43 @@ impl Chart { match chart_type { ChartType::LineChart => { - self.new_chart_line_chart(area_chart_series_list); + self.new_chart_line_chart(&area_chart_series_list); } ChartType::Line3DChart => { - self.new_chart_line_3d_chart(area_chart_series_list); + self.new_chart_line_3d_chart(&area_chart_series_list); } ChartType::PieChart => { - self.new_chart_pie_chart(area_chart_series_list); + self.new_chart_pie_chart(&area_chart_series_list); } ChartType::Pie3DChart => { - self.new_chart_pie_3d_chart(area_chart_series_list); + self.new_chart_pie_3d_chart(&area_chart_series_list); } ChartType::DoughnutChart => { - self.new_chart_doughnut_chart(area_chart_series_list); + self.new_chart_doughnut_chart(&area_chart_series_list); } ChartType::AreaChart => { - self.new_chart_area_chart(area_chart_series_list); + self.new_chart_area_chart(&area_chart_series_list); } ChartType::Area3DChart => { - self.new_chart_area_3d_chart(area_chart_series_list); + self.new_chart_area_3d_chart(&area_chart_series_list); } ChartType::BarChart => { - self.new_chart_bar_chart(area_chart_series_list); + self.new_chart_bar_chart(&area_chart_series_list); } ChartType::Bar3DChart => { - self.new_chart_bar_3d_chart(area_chart_series_list); + self.new_chart_bar_3d_chart(&area_chart_series_list); } ChartType::OfPieChart => { - self.new_chart_of_pie_chart(area_chart_series_list); + self.new_chart_of_pie_chart(&area_chart_series_list); } ChartType::BubbleChart => { - self.new_chart_bubble_chart(area_chart_series_list); + self.new_chart_bubble_chart(&area_chart_series_list); } ChartType::RadarChart => { - self.new_chart_radar_chart(area_chart_series_list); + self.new_chart_radar_chart(&area_chart_series_list); } ChartType::ScatterChart => { - self.new_chart_scatter_chart(area_chart_series_list); + self.new_chart_scatter_chart(&area_chart_series_list); } } @@ -418,7 +418,7 @@ impl Chart { } #[inline] - fn convert_series(area_chart_series_list: Vec<&str>, smooth: bool) -> AreaChartSeriesList { + fn convert_series(area_chart_series_list: &[&str], smooth: bool) -> AreaChartSeriesList { let mut acsl_obj = AreaChartSeriesList::default(); area_chart_series_list .into_iter() @@ -428,7 +428,7 @@ impl Chart { values .number_reference_mut() .formula_mut() - .set_address_str(area_chart_series); + .set_address_str(*area_chart_series); values .number_reference_mut() .numbering_cache_mut() @@ -451,8 +451,8 @@ impl Chart { acsl_obj } - pub(crate) fn new_chart_line_chart(&mut self, area_chart_series_list: Vec<&str>) { - let acsl_obj = Self::convert_series(area_chart_series_list, true); + pub(crate) fn new_chart_line_chart(&mut self, area_chart_series_list: &[&str]) { + let acsl_obj = Self::convert_series(&area_chart_series_list, true); let mut axis_id1 = AxisId::default(); axis_id1.set_val(213_468_160); @@ -585,7 +585,7 @@ impl Chart { self.two_cell_anchor.set_graphic_frame(graphic_frame); } - pub(crate) fn new_chart_line_3d_chart(&mut self, area_chart_series_list: Vec<&str>) { + pub(crate) fn new_chart_line_3d_chart(&mut self, area_chart_series_list: &[&str]) { let mut rotate_x = RotateX::default(); let mut rotate_y = RotateY::default(); let mut right_angle_axes = RightAngleAxes::default(); @@ -597,7 +597,7 @@ impl Chart { view_3d.set_rotate_y(rotate_y); view_3d.set_right_angle_axes(right_angle_axes); - let acsl_obj = Self::convert_series(area_chart_series_list, true); + let acsl_obj = Self::convert_series(&area_chart_series_list, true); let mut axis_id1 = AxisId::default(); axis_id1.set_val(213_468_160); @@ -737,8 +737,8 @@ impl Chart { self.two_cell_anchor.set_graphic_frame(graphic_frame); } - pub(crate) fn new_chart_pie_chart(&mut self, area_chart_series_list: Vec<&str>) { - let acsl_obj = Self::convert_series(area_chart_series_list, true); + pub(crate) fn new_chart_pie_chart(&mut self, area_chart_series_list: &[&str]) { + let acsl_obj = Self::convert_series(&area_chart_series_list, true); let mut show_leader_lines = ShowLeaderLines::default(); show_leader_lines.set_val(true); @@ -830,7 +830,7 @@ impl Chart { self.two_cell_anchor.set_graphic_frame(graphic_frame); } - pub(crate) fn new_chart_pie_3d_chart(&mut self, area_chart_series_list: Vec<&str>) { + pub(crate) fn new_chart_pie_3d_chart(&mut self, area_chart_series_list: &[&str]) { let mut rotate_x = RotateX::default(); let mut rotate_y = RotateY::default(); let mut right_angle_axes = RightAngleAxes::default(); @@ -842,7 +842,7 @@ impl Chart { view_3d.set_rotate_y(rotate_y); view_3d.set_right_angle_axes(right_angle_axes); - let acsl_obj = Self::convert_series(area_chart_series_list, true); + let acsl_obj = Self::convert_series(&area_chart_series_list, true); let mut show_leader_lines = ShowLeaderLines::default(); show_leader_lines.set_val(true); @@ -940,7 +940,7 @@ impl Chart { self.two_cell_anchor.set_graphic_frame(graphic_frame); } - pub(crate) fn new_chart_doughnut_chart(&mut self, area_chart_series_list: Vec<&str>) { + pub(crate) fn new_chart_doughnut_chart(&mut self, area_chart_series_list: &[&str]) { let mut acsl_obj = AreaChartSeriesList::default(); let mut acs_object = AreaChartSeries::default(); let mut idx = 0; @@ -950,7 +950,7 @@ impl Chart { let mut string_reference = StringReference::default(); string_reference .formula_mut() - .set_address_str(area_chart_series); + .set_address_str(*area_chart_series); let mut category_axis_data = CategoryAxisData::default(); category_axis_data.set_string_reference(string_reference); @@ -962,7 +962,7 @@ impl Chart { values .number_reference_mut() .formula_mut() - .set_address_str(area_chart_series); + .set_address_str(*area_chart_series); values .number_reference_mut() .numbering_cache_mut() @@ -1051,8 +1051,8 @@ impl Chart { self.two_cell_anchor.set_graphic_frame(graphic_frame); } - pub(crate) fn new_chart_area_chart(&mut self, area_chart_series_list: Vec<&str>) { - let acsl_obj = Self::convert_series(area_chart_series_list, true); + pub(crate) fn new_chart_area_chart(&mut self, area_chart_series_list: &[&str]) { + let acsl_obj = Self::convert_series(&area_chart_series_list, true); let mut axis_id1 = AxisId::default(); axis_id1.set_val(213_468_160); @@ -1179,7 +1179,7 @@ impl Chart { self.two_cell_anchor.set_graphic_frame(graphic_frame); } - pub(crate) fn new_chart_area_3d_chart(&mut self, area_chart_series_list: Vec<&str>) { + pub(crate) fn new_chart_area_3d_chart(&mut self, area_chart_series_list: &[&str]) { let mut rotate_x = RotateX::default(); let mut rotate_y = RotateY::default(); let mut right_angle_axes = RightAngleAxes::default(); @@ -1191,7 +1191,7 @@ impl Chart { view_3d.set_rotate_y(rotate_y); view_3d.set_right_angle_axes(right_angle_axes); - let acsl_obj = Self::convert_series(area_chart_series_list, true); + let acsl_obj = Self::convert_series(&area_chart_series_list, true); let mut axis_id1 = AxisId::default(); axis_id1.set_val(213_468_160); @@ -1326,8 +1326,8 @@ impl Chart { self.two_cell_anchor.set_graphic_frame(graphic_frame); } - pub(crate) fn new_chart_bar_chart(&mut self, area_chart_series_list: Vec<&str>) { - let acsl_obj = Self::convert_series(area_chart_series_list, false); + pub(crate) fn new_chart_bar_chart(&mut self, area_chart_series_list: &[&str]) { + let acsl_obj = Self::convert_series(&area_chart_series_list, false); let mut axis_id1 = AxisId::default(); axis_id1.set_val(213_468_160); @@ -1459,7 +1459,7 @@ impl Chart { self.two_cell_anchor.set_graphic_frame(graphic_frame); } - pub(crate) fn new_chart_bar_3d_chart(&mut self, area_chart_series_list: Vec<&str>) { + pub(crate) fn new_chart_bar_3d_chart(&mut self, area_chart_series_list: &[&str]) { let mut rotate_x = RotateX::default(); let mut rotate_y = RotateY::default(); let mut right_angle_axes = RightAngleAxes::default(); @@ -1471,7 +1471,7 @@ impl Chart { view_3d.set_rotate_y(rotate_y); view_3d.set_right_angle_axes(right_angle_axes); - let acsl_obj = Self::convert_series(area_chart_series_list, false); + let acsl_obj = Self::convert_series(&area_chart_series_list, false); let mut axis_id1 = AxisId::default(); axis_id1.set_val(213_468_160); @@ -1609,8 +1609,8 @@ impl Chart { self.two_cell_anchor.set_graphic_frame(graphic_frame); } - pub(crate) fn new_chart_of_pie_chart(&mut self, area_chart_series_list: Vec<&str>) { - let acsl_obj = Self::convert_series(area_chart_series_list, false); + pub(crate) fn new_chart_of_pie_chart(&mut self, area_chart_series_list: &[&str]) { + let acsl_obj = Self::convert_series(&area_chart_series_list, false); let mut show_leader_lines = ShowLeaderLines::default(); show_leader_lines.set_val(true); @@ -1695,7 +1695,7 @@ impl Chart { self.two_cell_anchor.set_graphic_frame(graphic_frame); } - pub(crate) fn new_chart_bubble_chart(&mut self, area_chart_series_list: Vec<&str>) { + pub(crate) fn new_chart_bubble_chart(&mut self, area_chart_series_list: &[&str]) { let mut acsl_obj = AreaChartSeriesList::default(); let mut acs_object = AreaChartSeries::default(); let mut idx = 0; @@ -1706,7 +1706,7 @@ impl Chart { x_values .number_reference_mut() .formula_mut() - .set_address_str(area_chart_series); + .set_address_str(*area_chart_series); x_values .number_reference_mut() .numbering_cache_mut() @@ -1720,7 +1720,7 @@ impl Chart { y_values .number_reference_mut() .formula_mut() - .set_address_str(area_chart_series); + .set_address_str(*area_chart_series); y_values .number_reference_mut() .numbering_cache_mut() @@ -1734,7 +1734,7 @@ impl Chart { bubble_size .number_reference_mut() .formula_mut() - .set_address_str(area_chart_series); + .set_address_str(*area_chart_series); bubble_size .number_reference_mut() .numbering_cache_mut() @@ -1920,8 +1920,8 @@ impl Chart { self.two_cell_anchor.set_graphic_frame(graphic_frame); } - pub(crate) fn new_chart_radar_chart(&mut self, area_chart_series_list: Vec<&str>) { - let acsl_obj = Self::convert_series(area_chart_series_list, true); + pub(crate) fn new_chart_radar_chart(&mut self, area_chart_series_list: &[&str]) { + let acsl_obj = Self::convert_series(&area_chart_series_list, true); let mut axis_id1 = AxisId::default(); axis_id1.set_val(213_468_160); @@ -2052,7 +2052,7 @@ impl Chart { self.two_cell_anchor.set_graphic_frame(graphic_frame); } - pub(crate) fn new_chart_scatter_chart(&mut self, area_chart_series_list: Vec<&str>) { + pub(crate) fn new_chart_scatter_chart(&mut self, area_chart_series_list: &[&str]) { let mut acsl_obj = AreaChartSeriesList::default(); let mut acs_object = AreaChartSeries::default(); let mut idx = 0; @@ -2063,7 +2063,7 @@ impl Chart { x_values .number_reference_mut() .formula_mut() - .set_address_str(area_chart_series); + .set_address_str(*area_chart_series); x_values .number_reference_mut() .numbering_cache_mut() @@ -2077,7 +2077,7 @@ impl Chart { y_values .number_reference_mut() .formula_mut() - .set_address_str(area_chart_series); + .set_address_str(*area_chart_series); y_values .number_reference_mut() .numbering_cache_mut() diff --git a/src/structs/data_bar.rs b/src/structs/data_bar.rs index bad98904..40121dd8 100644 --- a/src/structs/data_bar.rs +++ b/src/structs/data_bar.rs @@ -158,9 +158,9 @@ mod tests { let obj = read_data_bar( r#""#, ); - assert_eq!(obj.get_cfvo_collection().len(), 2); - assert_eq!(obj.get_color_collection().len(), 1); - assert_eq!(obj.get_color_collection()[0].get_argb_str(), "FF1E2761"); + assert_eq!(obj.cfvo_collection().len(), 2); + assert_eq!(obj.color_collection().len(), 1); + assert_eq!(obj.color_collection()[0].argb_str(), "FF1E2761"); } #[test] @@ -168,8 +168,8 @@ mod tests { let obj = read_data_bar( r#""#, ); - assert_eq!(obj.get_cfvo_collection().len(), 2); - assert_eq!(obj.get_color_collection().len(), 1); - assert_eq!(obj.get_color_collection()[0].get_argb_str(), "FF638EC6"); + assert_eq!(obj.cfvo_collection().len(), 2); + assert_eq!(obj.color_collection().len(), 1); + assert_eq!(obj.color_collection()[0].argb_str(), "FF638EC6"); } } diff --git a/src/structs/defined_name.rs b/src/structs/defined_name.rs index 78df6f5c..7ae31084 100644 --- a/src/structs/defined_name.rs +++ b/src/structs/defined_name.rs @@ -153,41 +153,41 @@ impl DefinedName { fn split_str>(value: S) -> Vec { let value = value.into(); - let char_list: Vec = value.chars().collect::>(); + let char_list = value.chars(); let mut is_pass_s = false; let mut is_pass_d = false; let mut is_pass_b = 0; let mut result: Vec = Vec::new(); let mut string = String::new(); - for c in &char_list { + for c in char_list { match c { '(' => { is_pass_b += 1; - string.push(*c); + string.push(c); } ')' => { is_pass_b -= 1; - string.push(*c); + string.push(c); } '\'' => { is_pass_s = !is_pass_s; - string.push(*c); + string.push(c); } '"' => { is_pass_d = !is_pass_d; if is_pass_s || is_pass_b != 0 { - string.push(*c); + string.push(c); } } ',' => { if !is_pass_s && !is_pass_d && is_pass_b == 0 { result.push(std::mem::take(&mut string)); } else { - string.push(*c); + string.push(c); } } _ => { - string.push(*c); + string.push(c); } } } diff --git a/src/structs/drawing/charts/plot_area.rs b/src/structs/drawing/charts/plot_area.rs index 9924dce4..c5ef70a7 100644 --- a/src/structs/drawing/charts/plot_area.rs +++ b/src/structs/drawing/charts/plot_area.rs @@ -640,98 +640,35 @@ impl PlotArea { } pub fn formula_mut(&mut self) -> Vec<&mut Formula> { - let mut result: Vec<&mut Formula> = Vec::default(); - if let Some(v) = &mut self.line_chart { - for ser in v.area_chart_series_list_mut().area_chart_series_mut() { - for formula in ser.formula_mut() { - result.push(formula); - } - } - } - if let Some(v) = &mut self.line_3d_chart { - for ser in v.area_chart_series_list_mut().area_chart_series_mut() { - for formula in ser.formula_mut() { - result.push(formula); - } - } - } - if let Some(v) = &mut self.pie_chart { - for ser in v.area_chart_series_list_mut().area_chart_series_mut() { - for formula in ser.formula_mut() { - result.push(formula); - } - } - } - if let Some(v) = &mut self.pie_3d_chart { - for ser in v.area_chart_series_list_mut().area_chart_series_mut() { - for formula in ser.formula_mut() { - result.push(formula); - } - } - } - if let Some(v) = &mut self.doughnut_chart { - for ser in v.area_chart_series_list_mut().area_chart_series_mut() { - for formula in ser.formula_mut() { - result.push(formula); - } - } - } - if let Some(v) = &mut self.scatter_chart { - for ser in v.area_chart_series_list_mut().area_chart_series_mut() { - for formula in ser.formula_mut() { - result.push(formula); - } - } - } - if let Some(v) = &mut self.bar_chart { - for ser in v.area_chart_series_list_mut().area_chart_series_mut() { - for formula in ser.formula_mut() { - result.push(formula); - } - } - } - if let Some(v) = &mut self.bar_3d_chart { - for ser in v.area_chart_series_list_mut().area_chart_series_mut() { - for formula in ser.formula_mut() { - result.push(formula); - } - } - } - if let Some(v) = &mut self.radar_chart { - for ser in v.area_chart_series_list_mut().area_chart_series_mut() { - for formula in ser.formula_mut() { - result.push(formula); - } - } - } - if let Some(v) = &mut self.bubble_chart { - for ser in v.area_chart_series_list_mut().area_chart_series_mut() { - for formula in ser.formula_mut() { - result.push(formula); - } - } - } - if let Some(v) = &mut self.area_chart { - for ser in v.area_chart_series_list_mut().area_chart_series_mut() { - for formula in ser.formula_mut() { - result.push(formula); - } - } - } - if let Some(v) = &mut self.area_3d_chart { - for ser in v.area_chart_series_list_mut().area_chart_series_mut() { - for formula in ser.formula_mut() { - result.push(formula); - } - } - } - if let Some(v) = &mut self.of_pie_chart { - for ser in v.area_chart_series_list_mut().area_chart_series_mut() { - for formula in ser.formula_mut() { - result.push(formula); - } - } + macro_rules! collect_formulas { + ($result:expr, $($field:expr),+ $(,)?) => { + $( + if let Some(v) = $field { + for ser in v.area_chart_series_list_mut().area_chart_series_mut() { + $result.extend(ser.formula_mut()); + } + } + )+ + }; } + + let mut result: Vec<&mut Formula> = Vec::default(); + collect_formulas!( + result, + &mut self.line_chart, + &mut self.line_3d_chart, + &mut self.pie_chart, + &mut self.pie_3d_chart, + &mut self.doughnut_chart, + &mut self.scatter_chart, + &mut self.bar_chart, + &mut self.bar_3d_chart, + &mut self.radar_chart, + &mut self.bubble_chart, + &mut self.area_chart, + &mut self.area_3d_chart, + &mut self.of_pie_chart, + ); result } diff --git a/src/structs/raw/raw_file.rs b/src/structs/raw/raw_file.rs index 6f4e68f7..b0468fb1 100644 --- a/src/structs/raw/raw_file.rs +++ b/src/structs/raw/raw_file.rs @@ -29,7 +29,7 @@ pub(crate) struct RawFile { impl RawFile { #[inline] pub(crate) fn file_name(&self) -> &str { - let v: Vec<&str> = self.file_target().split('/').collect(); + let v = self.file_target().split('/'); let object_name = v.last().unwrap(); object_name } diff --git a/src/structs/raw/raw_relationships.rs b/src/structs/raw/raw_relationships.rs index 4920a2b9..44288def 100644 --- a/src/structs/raw/raw_relationships.rs +++ b/src/structs/raw/raw_relationships.rs @@ -42,7 +42,7 @@ pub(crate) struct RawRelationships { impl RawRelationships { #[inline] pub(crate) fn file_name(&self) -> String { - let v: Vec<&str> = self.file_target().split('/').collect(); + let v = self.file_target().split('/'); let object_name = v.last().unwrap(); (*object_name).to_string() } diff --git a/src/structs/vml/spreadsheet/anchor.rs b/src/structs/vml/spreadsheet/anchor.rs index 6e30d32d..6ebeefd5 100644 --- a/src/structs/vml/spreadsheet/anchor.rs +++ b/src/structs/vml/spreadsheet/anchor.rs @@ -234,7 +234,7 @@ impl Anchor { } #[inline] - fn number(value: Option<&&str>) -> u32 { + fn number(value: Option<&str>) -> u32 { match value { Some(v) => (*v).trim().parse::().unwrap_or(0), None => 0, @@ -243,7 +243,7 @@ impl Anchor { #[inline] #[deprecated(since = "3.0.0", note = "Use number()")] - fn get_number(value: Option<&&str>) -> u32 { + fn get_number(value: Option<&str>) -> u32 { Self::number(value) } @@ -257,15 +257,15 @@ impl Anchor { reader, Event::Text(e) => { let text = crate::helper::utils::unescape_xml_text(&e); - let split_str: Vec<&str> = text.split(',').collect(); - self.set_left_column(Self::number(split_str.first())); - self.set_left_offset(Self::number(split_str.get(1))); - self.set_top_row(Self::number(split_str.get(2))); - self.set_top_offset(Self::number(split_str.get(3))); - self.set_right_column(Self::number(split_str.get(4))); - self.set_right_offset(Self::number(split_str.get(5))); - self.set_bottom_row(Self::number(split_str.get(6))); - self.set_bottom_offset(Self::number(split_str.get(7))); + let mut split_str = text.split(','); + self.set_left_column(Self::number(split_str.next())); + self.set_left_offset(Self::number(split_str.next())); + self.set_top_row(Self::number(split_str.next())); + self.set_top_offset(Self::number(split_str.next())); + self.set_right_column(Self::number(split_str.next())); + self.set_right_offset(Self::number(split_str.next())); + self.set_bottom_row(Self::number(split_str.next())); + self.set_bottom_offset(Self::number(split_str.next())); }, Event::End(ref e) => { if e.name().0 == b"x:Anchor" { diff --git a/src/structs/worksheet.rs b/src/structs/worksheet.rs index 87beed23..2e011cc0 100644 --- a/src/structs/worksheet.rs +++ b/src/structs/worksheet.rs @@ -2786,7 +2786,7 @@ impl Worksheet { if self.rows.row_dimension(row).is_some() { let mut indexes: Vec<(u32, u32)> = Vec::new(); { - let cells: Vec<&Cell> = self.cells.iter_cells_by_row(row).collect(); + let cells = self.cells.iter_cells_by_row(row); for cell in cells { if !cell.is_visually_empty() { return; From d49ea4c1b082064ddf1f517afb271b8cd9685946 Mon Sep 17 00:00:00 2001 From: AgentJill Date: Sun, 26 Jul 2026 00:28:39 +0530 Subject: [PATCH 2/3] make clippy happy --- src/structs/chart.rs | 18 +++++++++--------- src/structs/raw/raw_file.rs | 4 +--- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/src/structs/chart.rs b/src/structs/chart.rs index 210d5411..527e8b3f 100644 --- a/src/structs/chart.rs +++ b/src/structs/chart.rs @@ -421,7 +421,7 @@ impl Chart { fn convert_series(area_chart_series_list: &[&str], smooth: bool) -> AreaChartSeriesList { let mut acsl_obj = AreaChartSeriesList::default(); area_chart_series_list - .into_iter() + .iter() .enumerate() .for_each(|(idx, area_chart_series)| { let mut values = Values::default(); @@ -597,7 +597,7 @@ impl Chart { view_3d.set_rotate_y(rotate_y); view_3d.set_right_angle_axes(right_angle_axes); - let acsl_obj = Self::convert_series(&area_chart_series_list, true); + let acsl_obj = Self::convert_series(area_chart_series_list, true); let mut axis_id1 = AxisId::default(); axis_id1.set_val(213_468_160); @@ -738,7 +738,7 @@ impl Chart { } pub(crate) fn new_chart_pie_chart(&mut self, area_chart_series_list: &[&str]) { - let acsl_obj = Self::convert_series(&area_chart_series_list, true); + let acsl_obj = Self::convert_series(area_chart_series_list, true); let mut show_leader_lines = ShowLeaderLines::default(); show_leader_lines.set_val(true); @@ -842,7 +842,7 @@ impl Chart { view_3d.set_rotate_y(rotate_y); view_3d.set_right_angle_axes(right_angle_axes); - let acsl_obj = Self::convert_series(&area_chart_series_list, true); + let acsl_obj = Self::convert_series(area_chart_series_list, true); let mut show_leader_lines = ShowLeaderLines::default(); show_leader_lines.set_val(true); @@ -1052,7 +1052,7 @@ impl Chart { } pub(crate) fn new_chart_area_chart(&mut self, area_chart_series_list: &[&str]) { - let acsl_obj = Self::convert_series(&area_chart_series_list, true); + let acsl_obj = Self::convert_series(area_chart_series_list, true); let mut axis_id1 = AxisId::default(); axis_id1.set_val(213_468_160); @@ -1191,7 +1191,7 @@ impl Chart { view_3d.set_rotate_y(rotate_y); view_3d.set_right_angle_axes(right_angle_axes); - let acsl_obj = Self::convert_series(&area_chart_series_list, true); + let acsl_obj = Self::convert_series(area_chart_series_list, true); let mut axis_id1 = AxisId::default(); axis_id1.set_val(213_468_160); @@ -1327,7 +1327,7 @@ impl Chart { } pub(crate) fn new_chart_bar_chart(&mut self, area_chart_series_list: &[&str]) { - let acsl_obj = Self::convert_series(&area_chart_series_list, false); + let acsl_obj = Self::convert_series(area_chart_series_list, false); let mut axis_id1 = AxisId::default(); axis_id1.set_val(213_468_160); @@ -1471,7 +1471,7 @@ impl Chart { view_3d.set_rotate_y(rotate_y); view_3d.set_right_angle_axes(right_angle_axes); - let acsl_obj = Self::convert_series(&area_chart_series_list, false); + let acsl_obj = Self::convert_series(area_chart_series_list, false); let mut axis_id1 = AxisId::default(); axis_id1.set_val(213_468_160); @@ -1610,7 +1610,7 @@ impl Chart { } pub(crate) fn new_chart_of_pie_chart(&mut self, area_chart_series_list: &[&str]) { - let acsl_obj = Self::convert_series(&area_chart_series_list, false); + let acsl_obj = Self::convert_series(area_chart_series_list, false); let mut show_leader_lines = ShowLeaderLines::default(); show_leader_lines.set_val(true); diff --git a/src/structs/raw/raw_file.rs b/src/structs/raw/raw_file.rs index b0468fb1..42bc7230 100644 --- a/src/structs/raw/raw_file.rs +++ b/src/structs/raw/raw_file.rs @@ -29,9 +29,7 @@ pub(crate) struct RawFile { impl RawFile { #[inline] pub(crate) fn file_name(&self) -> &str { - let v = self.file_target().split('/'); - let object_name = v.last().unwrap(); - object_name + self.file_target().split('/').last().unwrap() } #[inline] From 38b807f7c0dc1bad7593d10a53da9450e6eb55b8 Mon Sep 17 00:00:00 2001 From: AgentJill Date: Sun, 26 Jul 2026 00:45:16 +0530 Subject: [PATCH 3/3] some more fight with clippy --- src/structs/chart.rs | 4 ++-- src/structs/raw/raw_file.rs | 2 +- src/structs/raw/raw_relationships.rs | 8 +++++--- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/structs/chart.rs b/src/structs/chart.rs index 527e8b3f..6d0423e1 100644 --- a/src/structs/chart.rs +++ b/src/structs/chart.rs @@ -452,7 +452,7 @@ impl Chart { } pub(crate) fn new_chart_line_chart(&mut self, area_chart_series_list: &[&str]) { - let acsl_obj = Self::convert_series(&area_chart_series_list, true); + let acsl_obj = Self::convert_series(area_chart_series_list, true); let mut axis_id1 = AxisId::default(); axis_id1.set_val(213_468_160); @@ -1921,7 +1921,7 @@ impl Chart { } pub(crate) fn new_chart_radar_chart(&mut self, area_chart_series_list: &[&str]) { - let acsl_obj = Self::convert_series(&area_chart_series_list, true); + let acsl_obj = Self::convert_series(area_chart_series_list, true); let mut axis_id1 = AxisId::default(); axis_id1.set_val(213_468_160); diff --git a/src/structs/raw/raw_file.rs b/src/structs/raw/raw_file.rs index 42bc7230..a8d4128e 100644 --- a/src/structs/raw/raw_file.rs +++ b/src/structs/raw/raw_file.rs @@ -29,7 +29,7 @@ pub(crate) struct RawFile { impl RawFile { #[inline] pub(crate) fn file_name(&self) -> &str { - self.file_target().split('/').last().unwrap() + self.file_target().split('/').next_back().unwrap() } #[inline] diff --git a/src/structs/raw/raw_relationships.rs b/src/structs/raw/raw_relationships.rs index 44288def..6f38312b 100644 --- a/src/structs/raw/raw_relationships.rs +++ b/src/structs/raw/raw_relationships.rs @@ -42,9 +42,11 @@ pub(crate) struct RawRelationships { impl RawRelationships { #[inline] pub(crate) fn file_name(&self) -> String { - let v = self.file_target().split('/'); - let object_name = v.last().unwrap(); - (*object_name).to_string() + self.file_target() + .split('/') + .next_back() + .unwrap() + .to_string() } #[inline]