From ebd05d9151a2a7256aea3c4dfcc0847e9bf822f2 Mon Sep 17 00:00:00 2001 From: "G. Endignoux" Date: Thu, 21 Dec 2023 14:56:10 +0100 Subject: [PATCH] Apply some Clippy suggestions. --- src/binary/read.rs | 4 ++-- src/cff.rs | 8 ++++---- src/cff/charstring.rs | 4 ++-- src/font.rs | 2 +- src/gsub.rs | 2 +- src/layout.rs | 11 +++++------ src/tables.rs | 20 +++++++------------- src/tables/glyf/variation.rs | 7 ++----- src/tables/variable_fonts.rs | 4 ++-- src/tables/variable_fonts/cvar.rs | 2 +- src/tables/variable_fonts/fvar.rs | 4 ++-- src/tables/variable_fonts/stat.rs | 8 ++++---- src/variations.rs | 9 ++++----- 13 files changed, 37 insertions(+), 48 deletions(-) diff --git a/src/binary/read.rs b/src/binary/read.rs index 9d46681..663fc9b 100644 --- a/src/binary/read.rs +++ b/src/binary/read.rs @@ -278,7 +278,7 @@ impl<'a> ReadScope<'a> { } pub fn ctxt(&self) -> ReadCtxt<'a> { - ReadCtxt::new(self.clone()) + ReadCtxt::new(*self) } pub fn read = ()>>(&self) -> Result, ParseError> { @@ -603,7 +603,7 @@ impl<'a> ReadCtxt<'a> { impl<'a> ReadBuf<'a> { pub fn scope(&'a self) -> ReadScope<'a> { - ReadScope::new(&*self.data) + ReadScope::new(&self.data) } pub fn into_data(self) -> Cow<'a, [u8]> { diff --git a/src/cff.rs b/src/cff.rs index 14ea317..56d78a2 100644 --- a/src/cff.rs +++ b/src/cff.rs @@ -1835,9 +1835,9 @@ where ctxt.read_array::>(range_count) } -fn write_cff_variant<'a, C: WriteContext>( +fn write_cff_variant( ctxt: &mut C, - variant: &CFFVariant<'a>, + variant: &CFFVariant<'_>, top_dict_delta: &mut DictDelta, ) -> Result<(), WriteError> { match variant { @@ -2011,10 +2011,10 @@ impl<'a> WriteBinary<&Self> for Type1Data<'a> { } /// Write the Private DICT and local subrs if present, returns the length of the Private DICT -fn write_private_dict_and_local_subr_index<'a, C: WriteContext>( +fn write_private_dict_and_local_subr_index( ctxt: &mut C, private_dict: &PrivateDict, - local_subr_index: &Option>, + local_subr_index: &Option>, ) -> Result { // Determine how big the Private DICT will be let private_dict_length = diff --git a/src/cff/charstring.rs b/src/cff/charstring.rs index ff1f92a..9e47a05 100644 --- a/src/cff/charstring.rs +++ b/src/cff/charstring.rs @@ -93,8 +93,8 @@ pub(crate) fn char_string_used_subrs<'a, 'f>( }) } -fn scan_used_subrs<'a, 'f>( - ctx: &mut CharStringScannerContext<'a, 'f>, +fn scan_used_subrs( + ctx: &mut CharStringScannerContext<'_, '_>, char_string: &[u8], depth: u8, stack: &mut ArgumentsStack<'_>, diff --git a/src/font.rs b/src/font.rs index 12663b2..9d23e38 100644 --- a/src/font.rs +++ b/src/font.rs @@ -433,7 +433,7 @@ impl Font { } Encoding::AppleRoman => match char_to_macroman(ch) { Some(char_code) => self.lookup_glyph_index_with_variation( - u32::from(char_code) as u32, + u32::from(char_code), match_presentation, used_selector, ), diff --git a/src/gsub.rs b/src/gsub.rs index b34568e..b006a66 100644 --- a/src/gsub.rs +++ b/src/gsub.rs @@ -686,7 +686,7 @@ fn apply_subst_context( } } match checked_add(len, changes) { - Some(new_len) => Ok(Some((new_len as usize, changes))), + Some(new_len) => Ok(Some((new_len, changes))), None => panic!("apply_subst_context: len < 0"), } } diff --git a/src/layout.rs b/src/layout.rs index 43b8397..93e34b5 100644 --- a/src/layout.rs +++ b/src/layout.rs @@ -1681,7 +1681,7 @@ impl ReadBinaryDep for CursivePos { .read_cache::(&mut cache.coverages.borrow_mut())?; let entry_exit_count = usize::from(ctxt.read_u16be()?); let entry_exit_records = ctxt - .read_array_dep::(entry_exit_count, scope.clone())? + .read_array_dep::(entry_exit_count, scope)? .read_to_vec()?; Ok(CursivePos { coverage, @@ -1819,7 +1819,7 @@ impl ReadBinaryDep for BaseArray { let scope = ctxt.scope(); let base_count = usize::from(ctxt.read_u16be()?); let base_records = ctxt - .read_array_dep::(base_count, (scope.clone(), mark_class_count))? + .read_array_dep::(base_count, (scope, mark_class_count))? .read_to_vec()?; Ok(BaseArray { base_records }) } @@ -1858,7 +1858,7 @@ impl ReadBinary for MarkArray { let scope = ctxt.scope(); let mark_count = usize::from(ctxt.read_u16be()?); let mark_records = ctxt - .read_array_dep::(mark_count, scope.clone())? + .read_array_dep::(mark_count, scope)? .read_to_vec()?; Ok(MarkArray { mark_records }) } @@ -2000,7 +2000,7 @@ impl ReadBinaryDep for LigatureAttach { let scope = ctxt.scope(); let component_count = usize::from(ctxt.read_u16be()?); let component_records = ctxt - .read_array_dep::(component_count, (scope.clone(), mark_class_count))? + .read_array_dep::(component_count, (scope, mark_class_count))? .read_to_vec()?; Ok(LigatureAttach { component_records }) } @@ -2942,8 +2942,7 @@ impl ClassDef { && (usize::from(glyph - start_glyph) < class_value_array.len()) { let class_index = glyph - start_glyph; - let class_value = class_value_array[usize::from(class_index)]; - class_value + class_value_array[usize::from(class_index)] } else { 0 } diff --git a/src/tables.rs b/src/tables.rs index a56dd2f..384f7f0 100644 --- a/src/tables.rs +++ b/src/tables.rs @@ -285,7 +285,7 @@ impl<'a> OpenTypeFont<'a> { self.offset_table(index) .map(|offset_table| OffsetTableFontProvider { offset_table: offset_table.into_owned(), - scope: self.scope.clone(), + scope: self.scope, }) } @@ -422,12 +422,9 @@ impl WriteBinary<&Self> for TableRecord { impl<'a> OffsetTable<'a> { pub fn find_table_record(&self, tag: u32) -> Option { - for table_record in &self.table_records { - if table_record.table_tag == tag { - return Some(table_record); - } - } - None + self.table_records + .iter() + .find(|table_record| table_record.table_tag == tag) } pub fn read_table( @@ -1452,15 +1449,12 @@ pub mod owned { ctxt.write_placeholder(string_offset, u16::try_from(string_start)?)?; // Write the string data - let lang_tags = name - .langtag_records - .iter() - .zip(langtag_record_offsets.into_iter()); + let lang_tags = name.langtag_records.iter().zip(langtag_record_offsets); let records = name .name_records .iter() .map(|rec| &rec.string) - .zip(name_record_offsets.into_iter()) + .zip(name_record_offsets) .chain(lang_tags); for (string, placeholder) in records { @@ -1468,7 +1462,7 @@ pub mod owned { placeholder, u16::try_from(ctxt.bytes_written() - string_start)?, )?; - ctxt.write_bytes(&string)?; + ctxt.write_bytes(string)?; } Ok(()) diff --git a/src/tables/glyf/variation.rs b/src/tables/glyf/variation.rs index a0bd7f8..963949e 100644 --- a/src/tables/glyf/variation.rs +++ b/src/tables/glyf/variation.rs @@ -279,7 +279,7 @@ fn glyph_deltas( return Ok(None); }; - let applicable = variations.determine_applicable(gvar, &instance); + let applicable = variations.determine_applicable(gvar, instance); // Now the deltas need to be calculated for each point. // The delta is multiplied by the scalar. The sum of deltas is applied to the @@ -424,8 +424,7 @@ fn infer_contour( let prev = explicit_deltas .range(target..=*contour_range.end()) .chain(explicit_deltas.range(*contour_range.start()..target)) - .rev() - .next() + .next_back() .unwrap(); let target = usize::safe_from(target); @@ -483,8 +482,6 @@ fn do_infer( prev_delta: i16, next_delta: i16, ) -> f32 { - let prev_delta = prev_delta; - let next_delta = next_delta; if prev_coord == next_coord { if prev_delta == next_delta { prev_delta as f32 diff --git a/src/tables/variable_fonts.rs b/src/tables/variable_fonts.rs index 303bbfc..f496471 100644 --- a/src/tables/variable_fonts.rs +++ b/src/tables/variable_fonts.rs @@ -664,7 +664,7 @@ impl<'data> PeakTuple<'data> for TupleVariationHeader<'data, Cvar> { type Table = CvarTable<'data>; fn peak_tuple<'a>(&'a self, _table: &'a Self::Table) -> Result, ParseError> { - self.peak_tuple().ok_or_else(|| ParseError::MissingValue) + self.peak_tuple().ok_or(ParseError::MissingValue) } } @@ -1103,7 +1103,7 @@ impl DeltaSetIndexMap<'_> { let entry_bytes = self .map_data .get(offset..(offset + entry_size)) - .ok_or_else(|| ParseError::BadIndex)?; + .ok_or(ParseError::BadIndex)?; // entry can be 1, 2, 3, or 4 bytes let entry = entry_bytes diff --git a/src/tables/variable_fonts/cvar.rs b/src/tables/variable_fonts/cvar.rs index 1f42006..5dff20b 100644 --- a/src/tables/variable_fonts/cvar.rs +++ b/src/tables/variable_fonts/cvar.rs @@ -32,7 +32,7 @@ impl CvarTable<'_> { let num_cvts = cvt.values.len() as u32; let mut values = cvt.values.iter().map(|val| val as f32).collect::>(); - for (scale, region) in self.store.determine_applicable(self, &instance) { + for (scale, region) in self.store.determine_applicable(self, instance) { let variation_data = region.variation_data(num_cvts, self.store.shared_point_numbers())?; for (cvt_index, delta) in variation_data.iter() { diff --git a/src/tables/variable_fonts/fvar.rs b/src/tables/variable_fonts/fvar.rs index 0f173f8..9190e97 100644 --- a/src/tables/variable_fonts/fvar.rs +++ b/src/tables/variable_fonts/fvar.rs @@ -123,7 +123,7 @@ impl FvarTable<'_> { let offset = i * instance_size; instance_array .get(offset..(offset + instance_size)) - .ok_or_else(|| ParseError::BadIndex) + .ok_or(ParseError::BadIndex) .and_then(|data| { ReadScope::new(data).read_dep::>((instance_size, axis_count)) }) @@ -268,7 +268,7 @@ impl std::ops::Deref for OwnedTuple { type Target = [F2Dot14]; fn deref(&self) -> &Self::Target { - &*self.0 + &self.0 } } diff --git a/src/tables/variable_fonts/stat.rs b/src/tables/variable_fonts/stat.rs index 5deb642..6ad5fad 100644 --- a/src/tables/variable_fonts/stat.rs +++ b/src/tables/variable_fonts/stat.rs @@ -217,7 +217,7 @@ impl<'a> StatTable<'a> { let offset = index * design_axis_size; self.design_axes_array .get(offset..(offset + design_axis_size)) - .ok_or_else(|| ParseError::BadIndex) + .ok_or(ParseError::BadIndex) .and_then(|data| ReadScope::new(data).read::()) } @@ -519,9 +519,9 @@ impl fmt::Debug for AxisRecord { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let tag = format!("{:?} ({})", self.axis_tag, DisplayTag(self.axis_tag)); f.debug_struct("AxisRecord") - .field(&"axis_tag", &tag) - .field(&"axis_name_id", &self.axis_name_id) - .field(&"axis_ordering", &self.axis_ordering) + .field("axis_tag", &tag) + .field("axis_name_id", &self.axis_name_id) + .field("axis_ordering", &self.axis_ordering) .finish() } } diff --git a/src/variations.rs b/src/variations.rs index faa04da..739e653 100644 --- a/src/variations.rs +++ b/src/variations.rs @@ -91,13 +91,13 @@ pub fn instance( let vhea_data = provider.table_data(tag::VHEA)?; let vhea = vhea_data .as_ref() - .map(|vhea_data| ReadScope::new(&vhea_data).read::()) + .map(|vhea_data| ReadScope::new(vhea_data).read::()) .transpose()?; let vmtx_data = provider.table_data(tag::VMTX)?; let vmtx = vhea .and_then(|vhea| { vmtx_data.as_ref().map(|vmtx_data| { - ReadScope::new(&vmtx_data).read_dep::>(( + ReadScope::new(vmtx_data).read_dep::>(( usize::from(maxp.num_glyphs), usize::from(vhea.num_h_metrics), )) @@ -158,7 +158,7 @@ pub fn instance( Some(gvar) => { glyf = apply_gvar( glyf, - &gvar, + gvar, &hmtx, vmtx.as_ref(), Some(&os2), @@ -664,8 +664,7 @@ fn create_hmtx_table<'b>( for glyph_record in glyf.records().iter() { let metric = match glyph_record { GlyfRecord::Parsed(glyph) => { - let bounding_box = - glyph.bounding_box().unwrap_or_else(|| BoundingBox::empty()); + let bounding_box = glyph.bounding_box().unwrap_or_else(BoundingBox::empty); // NOTE(unwrap): Phantom points are populated by apply_gvar let phantom_points = glyph.phantom_points().unwrap(); let pp1 = phantom_points[0].0;