Skip to content

Commit

Permalink
Apply some Clippy suggestions.
Browse files Browse the repository at this point in the history
  • Loading branch information
gendx authored and wezm committed Dec 21, 2023
1 parent eafc755 commit ebd05d9
Show file tree
Hide file tree
Showing 13 changed files with 37 additions and 48 deletions.
4 changes: 2 additions & 2 deletions src/binary/read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ impl<'a> ReadScope<'a> {
}

pub fn ctxt(&self) -> ReadCtxt<'a> {
ReadCtxt::new(self.clone())
ReadCtxt::new(*self)
}

pub fn read<T: ReadBinaryDep<Args<'a> = ()>>(&self) -> Result<T::HostType<'a>, ParseError> {
Expand Down Expand Up @@ -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]> {
Expand Down
8 changes: 4 additions & 4 deletions src/cff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1835,9 +1835,9 @@ where
ctxt.read_array::<Range<F, N>>(range_count)
}

fn write_cff_variant<'a, C: WriteContext>(
fn write_cff_variant<C: WriteContext>(
ctxt: &mut C,
variant: &CFFVariant<'a>,
variant: &CFFVariant<'_>,
top_dict_delta: &mut DictDelta,
) -> Result<(), WriteError> {
match variant {
Expand Down Expand Up @@ -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<C: WriteContext>(
ctxt: &mut C,
private_dict: &PrivateDict,
local_subr_index: &Option<MaybeOwnedIndex<'a>>,
local_subr_index: &Option<MaybeOwnedIndex<'_>>,
) -> Result<usize, WriteError> {
// Determine how big the Private DICT will be
let private_dict_length =
Expand Down
4 changes: 2 additions & 2 deletions src/cff/charstring.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<'_>,
Expand Down
2 changes: 1 addition & 1 deletion src/font.rs
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ impl<T: FontTableProvider> Font<T> {
}
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,
),
Expand Down
2 changes: 1 addition & 1 deletion src/gsub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,7 @@ fn apply_subst_context<T: GlyphData>(
}
}
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"),
}
}
Expand Down
11 changes: 5 additions & 6 deletions src/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1681,7 +1681,7 @@ impl ReadBinaryDep for CursivePos {
.read_cache::<Coverage>(&mut cache.coverages.borrow_mut())?;
let entry_exit_count = usize::from(ctxt.read_u16be()?);
let entry_exit_records = ctxt
.read_array_dep::<EntryExitRecord>(entry_exit_count, scope.clone())?
.read_array_dep::<EntryExitRecord>(entry_exit_count, scope)?
.read_to_vec()?;
Ok(CursivePos {
coverage,
Expand Down Expand Up @@ -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::<BaseRecord>(base_count, (scope.clone(), mark_class_count))?
.read_array_dep::<BaseRecord>(base_count, (scope, mark_class_count))?
.read_to_vec()?;
Ok(BaseArray { base_records })
}
Expand Down Expand Up @@ -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::<MarkRecord>(mark_count, scope.clone())?
.read_array_dep::<MarkRecord>(mark_count, scope)?
.read_to_vec()?;
Ok(MarkArray { mark_records })
}
Expand Down Expand Up @@ -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::<ComponentRecord>(component_count, (scope.clone(), mark_class_count))?
.read_array_dep::<ComponentRecord>(component_count, (scope, mark_class_count))?
.read_to_vec()?;
Ok(LigatureAttach { component_records })
}
Expand Down Expand Up @@ -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
}
Expand Down
20 changes: 7 additions & 13 deletions src/tables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})
}

Expand Down Expand Up @@ -422,12 +422,9 @@ impl WriteBinary<&Self> for TableRecord {

impl<'a> OffsetTable<'a> {
pub fn find_table_record(&self, tag: u32) -> Option<TableRecord> {
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(
Expand Down Expand Up @@ -1452,23 +1449,20 @@ 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 {
ctxt.write_placeholder(
placeholder,
u16::try_from(ctxt.bytes_written() - string_start)?,
)?;
ctxt.write_bytes(&string)?;
ctxt.write_bytes(string)?;
}

Ok(())
Expand Down
7 changes: 2 additions & 5 deletions src/tables/glyf/variation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/tables/variable_fonts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Tuple<'data>, ParseError> {
self.peak_tuple().ok_or_else(|| ParseError::MissingValue)
self.peak_tuple().ok_or(ParseError::MissingValue)
}
}

Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/tables/variable_fonts/cvar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<Vec<_>>();

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() {
Expand Down
4 changes: 2 additions & 2 deletions src/tables/variable_fonts/fvar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<InstanceRecord<'_>>((instance_size, axis_count))
})
Expand Down Expand Up @@ -268,7 +268,7 @@ impl std::ops::Deref for OwnedTuple {
type Target = [F2Dot14];

fn deref(&self) -> &Self::Target {
&*self.0
&self.0
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/tables/variable_fonts/stat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<AxisRecord>())
}

Expand Down Expand Up @@ -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()
}
}
Expand Down
9 changes: 4 additions & 5 deletions src/variations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<HheaTable>())
.map(|vhea_data| ReadScope::new(vhea_data).read::<HheaTable>())
.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::<HmtxTable<'_>>((
ReadScope::new(vmtx_data).read_dep::<HmtxTable<'_>>((
usize::from(maxp.num_glyphs),
usize::from(vhea.num_h_metrics),
))
Expand Down Expand Up @@ -158,7 +158,7 @@ pub fn instance(
Some(gvar) => {
glyf = apply_gvar(
glyf,
&gvar,
gvar,
&hmtx,
vmtx.as_ref(),
Some(&os2),
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit ebd05d9

Please sign in to comment.