Skip to content

Commit fdae82c

Browse files
committed
Simplify fallible_collections usages with updated version
This allows us to remove unnecessary `try_clone`s now that we can use TryHashMap::remove instead and simplifies unwrap_or_else calls to unwrap_or_default.
1 parent a29017d commit fdae82c

File tree

2 files changed

+10
-31
lines changed

2 files changed

+10
-31
lines changed

mp4parse/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ travis-ci = { repository = "https://github.com/mozilla/mp4parse-rust" }
2727
[dependencies]
2828
byteorder = "1.2.1"
2929
bitreader = { version = "0.3.2" }
30-
fallible_collections = { version = "0.2", features = ["std_io"] }
30+
fallible_collections = { version = "0.3", features = ["std_io"] }
3131
hashbrown = "0.9"
3232
num-traits = "=0.2.10"
3333
log = "0.4"

mp4parse/src/lib.rs

Lines changed: 9 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ extern crate fallible_collections;
1313
extern crate num_traits;
1414
use bitreader::{BitReader, ReadInto};
1515
use byteorder::{ReadBytesExt, WriteBytesExt};
16-
use fallible_collections::TryClone;
16+
1717
use fallible_collections::TryRead;
1818
use fallible_collections::TryReserveError;
1919
use num_traits::Num;
@@ -1420,8 +1420,8 @@ fn read_avif_meta<T: Read + Offset>(src: &mut BMFFBox<T>) -> Result<AvifMeta> {
14201420
}
14211421

14221422
Ok(AvifMeta {
1423-
properties: properties.unwrap_or_else(TryVec::new),
1424-
item_references: item_references.unwrap_or_else(TryVec::new),
1423+
properties: properties.unwrap_or_default(),
1424+
item_references: item_references.unwrap_or_default(),
14251425
primary_item_id,
14261426
iloc_items: iloc_items.ok_or(Error::InvalidData("iloc missing"))?,
14271427
})
@@ -1562,7 +1562,7 @@ fn read_iref<T: Read>(src: &mut BMFFBox<T>) -> Result<TryVec<SingleItemTypeRefer
15621562
fn read_iprp<T: Read>(src: &mut BMFFBox<T>) -> Result<TryVec<AssociatedProperty>> {
15631563
let mut iter = src.box_iter();
15641564

1565-
let properties = match iter.next_box()? {
1565+
let mut properties = match iter.next_box()? {
15661566
Some(mut b) if b.head.name == BoxType::ItemPropertyContainerBox => read_ipco(&mut b),
15671567
Some(_) => Err(Error::InvalidData("unexpected iprp child")),
15681568
None => Err(Error::UnexpectedEOF),
@@ -1571,7 +1571,7 @@ fn read_iprp<T: Read>(src: &mut BMFFBox<T>) -> Result<TryVec<AssociatedProperty>
15711571
// Per HEIF (ISO 23008-12:2017) § 9.3.1: There can be zero or more ipma boxes
15721572
// but "There shall be at most one ItemPropertyAssociationbox with a given
15731573
// pair of values of version and flags"
1574-
let mut ipma_version_and_flag_values_seen = TryHashMap::with_capacity(1)?;
1574+
let mut ipma_version_and_flag_values_seen = TryVec::with_capacity(1)?;
15751575
let mut associated = TryVec::new();
15761576

15771577
while let Some(mut b) = iter.next_box()? {
@@ -1580,12 +1580,10 @@ fn read_iprp<T: Read>(src: &mut BMFFBox<T>) -> Result<TryVec<AssociatedProperty>
15801580
}
15811581

15821582
let version_and_flags = read_fullbox_extra(&mut b)?;
1583-
if ipma_version_and_flag_values_seen
1584-
.insert(version_and_flags, ())?
1585-
.is_some()
1586-
{
1583+
if ipma_version_and_flag_values_seen.contains(&version_and_flags) {
15871584
return Err(Error::InvalidData("Duplicate ipma with same version/flags"));
15881585
}
1586+
ipma_version_and_flag_values_seen.push(version_and_flags)?;
15891587
let associations = read_ipma(&mut b, version_and_flags)?;
15901588
for a in associations {
15911589
if a.property_index == 0 {
@@ -1595,10 +1593,10 @@ fn read_iprp<T: Read>(src: &mut BMFFBox<T>) -> Result<TryVec<AssociatedProperty>
15951593
continue;
15961594
}
15971595

1598-
if let Some(prop) = properties.get(&a.property_index) {
1596+
if let Some(property) = properties.remove(&a.property_index) {
15991597
associated.push(AssociatedProperty {
16001598
item_id: a.item_id,
1601-
property: prop.try_clone()?,
1599+
property,
16021600
})?;
16031601
}
16041602
}
@@ -1617,16 +1615,6 @@ pub enum ItemProperty {
16171615
Unsupported,
16181616
}
16191617

1620-
impl TryClone for ItemProperty {
1621-
fn try_clone(&self) -> Result<Self, TryReserveError> {
1622-
Ok(match self {
1623-
Self::Channels(val) => Self::Channels(val.try_clone()?),
1624-
Self::AuxiliaryType(val) => Self::AuxiliaryType(val.try_clone()?),
1625-
Self::Unsupported => Self::Unsupported,
1626-
})
1627-
}
1628-
}
1629-
16301618
/// For storing ItemPropertyAssociation data
16311619
/// See HEIF (ISO 23008-12:2017) § 9.3.1
16321620
struct Association {
@@ -1726,15 +1714,6 @@ pub struct AuxiliaryTypeProperty {
17261714
aux_subtype: TryString,
17271715
}
17281716

1729-
impl TryClone for AuxiliaryTypeProperty {
1730-
fn try_clone(&self) -> Result<Self, TryReserveError> {
1731-
Ok(AuxiliaryTypeProperty {
1732-
aux_type: self.aux_type.try_clone()?,
1733-
aux_subtype: self.aux_subtype.try_clone()?,
1734-
})
1735-
}
1736-
}
1737-
17381717
/// Parse image properties for auxiliary images
17391718
/// See HEIF (ISO 23008-12:2017) § 6.5.8
17401719
fn read_auxc<T: Read>(src: &mut BMFFBox<T>) -> Result<AuxiliaryTypeProperty> {

0 commit comments

Comments
 (0)