From a0e15050fc086bb8f645e8286ba5454f363ab59d Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Mon, 22 Jun 2020 10:45:59 +0200 Subject: [PATCH] algorithm conversions --- src/KaxCues.cpp | 51 +++++++++++++++++++++------------------------ src/KaxSeekHead.cpp | 15 +++++++------ 2 files changed, 31 insertions(+), 35 deletions(-) diff --git a/src/KaxCues.cpp b/src/KaxCues.cpp index 0fd1e54..2fc9885 100644 --- a/src/KaxCues.cpp +++ b/src/KaxCues.cpp @@ -67,11 +67,11 @@ bool KaxCues::AddBlockGroup(const KaxBlockGroup & BlockRef) bool KaxCues::AddBlockBlob(const KaxBlockBlob & BlockReference) { // Do not add the element if it's already present. - std::vector::iterator ListIdx; - - for (ListIdx = myTempReferences.begin(); ListIdx != myTempReferences.end(); ++ListIdx) - if (*ListIdx == &BlockReference) - return true; + bool present = std::any_of(myTempReferences.begin(), myTempReferences.end(), + [&](const KaxBlockBlob *myTempReference) { return myTempReference == &BlockReference; }); + if (present) { + return true; + } myTempReferences.push_back(&BlockReference); return true; @@ -80,34 +80,31 @@ bool KaxCues::AddBlockBlob(const KaxBlockBlob & BlockReference) void KaxCues::PositionSet(const KaxBlockBlob & BlockReference) { // look for the element in the temporary references - std::vector::iterator ListIdx; - - for (ListIdx = myTempReferences.begin(); ListIdx != myTempReferences.end(); ++ListIdx) { - if (*ListIdx == &BlockReference) { - // found, now add the element to the entry list - auto & NewPoint = AddNewChild(*this); - NewPoint.PositionSet(BlockReference, GlobalTimecodeScale()); - myTempReferences.erase(ListIdx); - break; - } + auto it = std::find_if(myTempReferences.begin(), myTempReferences.end(), + [&](const KaxBlockBlob *myTempReference){ return myTempReference == &BlockReference; }); + + if (it != myTempReferences.end()) { + // found, now add the element to the entry list + auto & NewPoint = AddNewChild(*this); + NewPoint.PositionSet(BlockReference, GlobalTimecodeScale()); + myTempReferences.erase(it); } } void KaxCues::PositionSet(const KaxBlockGroup & BlockRef) { // look for the element in the temporary references - std::vector::iterator ListIdx; - - for (ListIdx = myTempReferences.begin(); ListIdx != myTempReferences.end(); ++ListIdx) { - const KaxInternalBlock &refTmp = **ListIdx; - if (refTmp.GlobalTimecode() == BlockRef.GlobalTimecode() && - refTmp.TrackNum() == BlockRef.TrackNumber()) { - // found, now add the element to the entry list - auto & NewPoint = AddNewChild(*this); - NewPoint.PositionSet(**ListIdx, GlobalTimecodeScale()); - myTempReferences.erase(ListIdx); - break; - } + auto it = std::find_if(myTempReferences.begin(), myTempReferences.end(), + [&](const KaxBlockBlob *myTempReference) + { const KaxInternalBlock &refTmp = *myTempReference; + return refTmp.GlobalTimecode() == BlockRef.GlobalTimecode() + && refTmp.TrackNum() == BlockRef.TrackNumber(); }); + + if(it != myTempReferences.end()) { + // found, now add the element to the entry list + auto & NewPoint = AddNewChild(*this); + NewPoint.PositionSet(**it, GlobalTimecodeScale()); + myTempReferences.erase(it); } } diff --git a/src/KaxSeekHead.cpp b/src/KaxSeekHead.cpp index f1ed42d..6372fe3 100644 --- a/src/KaxSeekHead.cpp +++ b/src/KaxSeekHead.cpp @@ -68,14 +68,13 @@ KaxSeek * KaxSeekHead::FindFirstOf(const EbmlCallbacks & Callbacks) const while (aElt != nullptr) { KaxSeekID * aId = nullptr; EBML_MASTER_ITERATOR Itr; - for (Itr = aElt->begin(); Itr != aElt->end(); ++Itr) { - if (EbmlId(*(*Itr)) == EBML_ID(KaxSeekID)) { - aId = static_cast(*Itr); - EbmlId aEbmlId(aId->GetBuffer(), aId->GetSize()); - if (aEbmlId == EBML_INFO_ID(Callbacks)) { - return aElt; - } - break; + auto it = std::find_if(aElt->begin(), aElt->end(), [&](EbmlElement *Elt) + { return (EbmlId(*Elt) == EBML_ID(KaxSeekID)); }); + if (it != aElt->end()) { + aId = static_cast(*it); + EbmlId aEbmlId(aId->GetBuffer(), aId->GetSize()); + if (aEbmlId == EBML_INFO_ID(Callbacks)) { + return aElt; } } aElt = static_cast(FindNextElt(*aElt)); -- 2.40.0