Simplify code
This commit is contained in:
parent
31c1bb47e6
commit
b740d2c1e0
|
@ -272,8 +272,7 @@ TagType *GenericContainer<FileInfoType, TagType, TrackType, ElementType>::create
|
|||
}
|
||||
|
||||
// a new tag must be created
|
||||
m_tags.emplace_back(std::make_unique<TagType>());
|
||||
auto &tag = m_tags.back();
|
||||
const auto &tag = m_tags.emplace_back(std::make_unique<TagType>());
|
||||
tag->setTarget(target);
|
||||
return tag.get();
|
||||
}
|
||||
|
@ -281,7 +280,7 @@ TagType *GenericContainer<FileInfoType, TagType, TrackType, ElementType>::create
|
|||
template <class FileInfoType, class TagType, class TrackType, class ElementType>
|
||||
bool GenericContainer<FileInfoType, TagType, TrackType, ElementType>::removeTag(Tag *tag)
|
||||
{
|
||||
if (auto size = m_tags.size()) {
|
||||
if (const auto size = m_tags.size()) {
|
||||
m_tags.erase(std::remove_if(m_tags.begin(), m_tags.end(),
|
||||
[tag](const std::unique_ptr<TagType> &existingTag) -> bool { return static_cast<Tag *>(existingTag.get()) == tag; }),
|
||||
m_tags.end());
|
||||
|
@ -315,10 +314,12 @@ inline void GenericContainer<FileInfoType, TagType, TrackType, ElementType>::rem
|
|||
template <class FileInfoType, class TagType, class TrackType, class ElementType>
|
||||
bool GenericContainer<FileInfoType, TagType, TrackType, ElementType>::addTrack(TrackType *track)
|
||||
{
|
||||
if (areTracksParsed() && supportsTrackModifications()) {
|
||||
if (!areTracksParsed() || !supportsTrackModifications()) {
|
||||
return false;
|
||||
}
|
||||
// ensure ID is unique
|
||||
auto id = track->id();
|
||||
ensureIdIsUnique:
|
||||
ensureIdIsUnique:
|
||||
for (const auto &existingTrack : m_tracks) {
|
||||
if (existingTrack->id() == id) {
|
||||
++id;
|
||||
|
@ -329,15 +330,15 @@ bool GenericContainer<FileInfoType, TagType, TrackType, ElementType>::addTrack(T
|
|||
|
||||
m_tracks.emplace_back(track);
|
||||
return m_tracksAltered = true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
template <class FileInfoType, class TagType, class TrackType, class ElementType>
|
||||
bool GenericContainer<FileInfoType, TagType, TrackType, ElementType>::removeTrack(AbstractTrack *track)
|
||||
{
|
||||
bool removed = false;
|
||||
if (areTracksParsed() && supportsTrackModifications() && !m_tracks.empty()) {
|
||||
if (!areTracksParsed() || !supportsTrackModifications() || m_tracks.empty()) {
|
||||
return false;
|
||||
}
|
||||
auto removed = false;
|
||||
for (auto i = m_tracks.end() - 1, begin = m_tracks.begin();; --i) {
|
||||
if (static_cast<AbstractTrack *>(i->get()) == track) {
|
||||
i->release();
|
||||
|
@ -351,7 +352,6 @@ bool GenericContainer<FileInfoType, TagType, TrackType, ElementType>::removeTrac
|
|||
if (removed) {
|
||||
m_tracksAltered = true;
|
||||
}
|
||||
}
|
||||
return removed;
|
||||
}
|
||||
|
||||
|
|
|
@ -955,10 +955,10 @@ void MatroskaContainer::internalMakeFile(Diagnostics &diag, AbortableProgressFee
|
|||
// calculate size of "Tags"-element
|
||||
for (auto &tag : tags()) {
|
||||
try {
|
||||
tagMaker.emplace_back(tag->prepareMaking(diag));
|
||||
if (tagMaker.back().requiredSize() > 3) {
|
||||
const auto &maker = tagMaker.emplace_back(tag->prepareMaking(diag));
|
||||
if (maker.requiredSize() > 3) {
|
||||
// a tag of 3 bytes size is empty and can be skipped
|
||||
tagElementsSize += tagMaker.back().requiredSize();
|
||||
tagElementsSize += maker.requiredSize();
|
||||
}
|
||||
} catch (const Failure &) {
|
||||
}
|
||||
|
@ -969,10 +969,10 @@ void MatroskaContainer::internalMakeFile(Diagnostics &diag, AbortableProgressFee
|
|||
for (auto &attachment : m_attachments) {
|
||||
if (!attachment->isIgnored()) {
|
||||
try {
|
||||
attachmentMaker.emplace_back(attachment->prepareMaking(diag));
|
||||
if (attachmentMaker.back().requiredSize() > 3) {
|
||||
const auto &maker = attachmentMaker.emplace_back(attachment->prepareMaking(diag));
|
||||
if (maker.requiredSize() > 3) {
|
||||
// an attachment of 3 bytes size is empty and can be skipped
|
||||
attachedFileElementsSize += attachmentMaker.back().requiredSize();
|
||||
attachedFileElementsSize += maker.requiredSize();
|
||||
}
|
||||
} catch (const Failure &) {
|
||||
}
|
||||
|
@ -984,10 +984,10 @@ void MatroskaContainer::internalMakeFile(Diagnostics &diag, AbortableProgressFee
|
|||
// calculate size of "Tracks"-element
|
||||
for (auto &track : tracks()) {
|
||||
try {
|
||||
trackHeaderMaker.emplace_back(track->prepareMakingHeader(diag));
|
||||
if (trackHeaderMaker.back().requiredSize() > 3) {
|
||||
const auto &maker = trackHeaderMaker.emplace_back(track->prepareMakingHeader(diag));
|
||||
if (maker.requiredSize() > 3) {
|
||||
// a track header of 3 bytes size is empty and can be skipped
|
||||
trackHeaderElementsSize += trackHeaderMaker.back().requiredSize();
|
||||
trackHeaderElementsSize += maker.requiredSize();
|
||||
}
|
||||
} catch (const Failure &) {
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue