From: Rosen Penev Date: Sat, 24 Sep 2022 21:21:07 +0000 (-0700) Subject: clang-tidy: add const X-Git-Tag: release-1.7.0~3 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=43dba782ac5199d5571437e51021456a320fb636;p=libmatroska clang-tidy: add const Found with misc-const-correctness Also manually simplified several any_of/find_if calls. Also added manual auto with static_cast Signed-off-by: Rosen Penev --- diff --git a/src/KaxBlock.cpp b/src/KaxBlock.cpp index 417e4d1..4d069de 100644 --- a/src/KaxBlock.cpp +++ b/src/KaxBlock.cpp @@ -251,8 +251,8 @@ filepos_t KaxBlockVirtual::UpdateSize(bool /* bSaveDefault */, bool /* bForceRen } assert(ParentCluster != nullptr); - int16 ActualTimecode = ParentCluster->GetBlockLocalTimecode(Timecode); - big_int16 b16(ActualTimecode); + const int16 ActualTimecode = ParentCluster->GetBlockLocalTimecode(Timecode); + const auto b16 = big_int16(ActualTimecode); b16.Fill(cursor); cursor += 2; @@ -294,8 +294,8 @@ filepos_t KaxInternalBlock::RenderData(IOCallback & output, bool /* bForceRender } assert(ParentCluster != nullptr); - int16 ActualTimecode = ParentCluster->GetBlockLocalTimecode(Timecode); - big_int16 b16(ActualTimecode); + const int16 ActualTimecode = ParentCluster->GetBlockLocalTimecode(Timecode); + const auto b16 = big_int16(ActualTimecode); b16.Fill(cursor); cursor += 2; @@ -478,7 +478,7 @@ filepos_t KaxInternalBlock::ReadData(IOCallback & input, ScopeMode ReadFully) LocalTimecode = static_cast(Mem.GetUInt16BE()); bLocalTimecodeUsed = true; - uint8 Flags = Mem.GetUInt8(); + const uint8 Flags = Mem.GetUInt8(); if (EbmlId(*this) == EBML_ID(KaxSimpleBlock)) { bIsKeyframe = (Flags & 0x80) != 0; bIsDiscardable = (Flags & 0x01) != 0; @@ -496,7 +496,7 @@ filepos_t KaxInternalBlock::ReadData(IOCallback & input, ScopeMode ReadFully) } else { // read the number of frames in the lace uint32 LastBufferSize = GetSize() - BlockHeadSize - 1; // 1 for number of frame - uint8 FrameNum = Mem.GetUInt8(); // number of frames in the lace - 1 + const uint8 FrameNum = Mem.GetUInt8(); // number of frames in the lace - 1 // read the list of frame sizes uint8 Index; int32 FrameSize; @@ -563,7 +563,7 @@ filepos_t KaxInternalBlock::ReadData(IOCallback & input, ScopeMode ReadFully) } binary *BufferEnd = BufferStart + GetSize(); - size_t NumFrames = myBuffers.size(); + const size_t NumFrames = myBuffers.size(); // Sanity checks for frame pointers and boundaries. for (size_t Index = 0; Index < NumFrames; ++Index) { @@ -625,7 +625,7 @@ filepos_t KaxInternalBlock::ReadData(IOCallback & input, ScopeMode ReadFully) // read the number of frames in the lace const uint32 TotalLacedSize = GetSize() - BlockHeadSize - 1; // 1 for number of frame uint32 LastBufferSize = TotalLacedSize; - uint8 FrameNum = _TempHead[0]; // number of frames in the lace - 1 + const uint8 FrameNum = _TempHead[0]; // number of frames in the lace - 1 // read the list of frame sizes uint8 Index; uint32 FrameSize; @@ -736,7 +736,7 @@ bool KaxBlockGroup::AddFrame(const KaxTrackEntry & track, uint64 timecode, DataB assert(ParentCluster != nullptr); theBlock.SetParent(*ParentCluster); ParentTrack = &track; - bool bRes = theBlock.AddFrame(track, timecode, buffer, lacing); + const bool bRes = theBlock.AddFrame(track, timecode, buffer, lacing); auto & thePastRef = GetChild(*this); thePastRef.SetReferencedBlock(PastBlock); @@ -755,7 +755,7 @@ bool KaxBlockGroup::AddFrame(const KaxTrackEntry & track, uint64 timecode, DataB assert(ParentCluster != nullptr); theBlock.SetParent(*ParentCluster); ParentTrack = &track; - bool bRes = theBlock.AddFrame(track, timecode, buffer, lacing); + bool const bRes = theBlock.AddFrame(track, timecode, buffer, lacing); auto & thePastRef = GetChild(*this); thePastRef.SetReferencedBlock(PastBlock); @@ -774,7 +774,7 @@ bool KaxBlockGroup::AddFrame(const KaxTrackEntry & track, uint64 timecode, DataB assert(ParentCluster != nullptr); theBlock.SetParent(*ParentCluster); ParentTrack = &track; - bool bRes = theBlock.AddFrame(track, timecode, buffer, lacing); + const bool bRes = theBlock.AddFrame(track, timecode, buffer, lacing); if (PastBlock != nullptr) { auto & thePastRef = GetChild(*this); @@ -797,14 +797,14 @@ bool KaxBlockGroup::AddFrame(const KaxTrackEntry & track, uint64 timecode, DataB uint64 KaxBlockGroup::GlobalTimecode() const { assert(ParentCluster != nullptr); // impossible otherwise - KaxInternalBlock & MyBlock = *static_cast(this->FindElt(EBML_INFO(KaxBlock))); + const auto& MyBlock = *static_cast(this->FindElt(EBML_INFO(KaxBlock))); return MyBlock.GlobalTimecode(); } uint16 KaxBlockGroup::TrackNumber() const { - KaxInternalBlock & MyBlock = *static_cast(this->FindElt(EBML_INFO(KaxBlock))); + const auto& MyBlock = *static_cast(this->FindElt(EBML_INFO(KaxBlock))); return MyBlock.TrackNum(); } @@ -848,7 +848,7 @@ const KaxReferenceBlock & KaxBlockGroup::Reference(unsigned int Index) const void KaxBlockGroup::ReleaseFrames() { - KaxInternalBlock & MyBlock = *static_cast(this->FindElt(EBML_INFO(KaxBlock))); + auto& MyBlock = *static_cast(this->FindElt(EBML_INFO(KaxBlock))); MyBlock.ReleaseFrames(); } @@ -868,8 +868,8 @@ void KaxInternalBlock::ReleaseFrames() void KaxBlockGroup::SetBlockDuration(uint64 TimeLength) { assert(ParentTrack != nullptr); - int64 scale = ParentTrack->GlobalTimecodeScale(); - KaxBlockDuration & myDuration = *static_cast(FindFirstElt(EBML_INFO(KaxBlockDuration), true)); + const int64 scale = ParentTrack->GlobalTimecodeScale(); + auto& myDuration = *static_cast(FindFirstElt(EBML_INFO(KaxBlockDuration), true)); *(static_cast(&myDuration)) = TimeLength / static_cast(scale); } diff --git a/src/KaxCluster.cpp b/src/KaxCluster.cpp index 8903902..a2adaff 100644 --- a/src/KaxCluster.cpp +++ b/src/KaxCluster.cpp @@ -154,10 +154,10 @@ filepos_t KaxCluster::Render(IOCallback & output, KaxCues & CueToUpdate, bool bS // SilentTracks handling // check the parent cluster for existing tracks and see if they are contained in this cluster or not if (bSilentTracksUsed) { - KaxTracks & MyTracks = *static_cast(ParentSegment->FindElt(EBML_INFO(KaxTracks))); + const auto& MyTracks = *static_cast(ParentSegment->FindElt(EBML_INFO(KaxTracks))); for (auto&& Trk : MyTracks) { if (EbmlId(*Trk) == EBML_ID(KaxTrackEntry)) { - KaxTrackEntry & entry = *static_cast(Trk); + const auto& entry = *static_cast(Trk); auto tracknum = static_cast(entry.TrackNumber()); auto track = std::find_if(ElementList.begin(), ElementList.end(), [=](EbmlElement *element) { return EbmlId(*element) == EBML_ID(KaxBlockGroup) && static_cast(element)->TrackNumber() == tracknum; }); @@ -192,10 +192,10 @@ filepos_t KaxCluster::Render(IOCallback & output, KaxCues & CueToUpdate, bool bS // SilentTracks handling // check the parent cluster for existing tracks and see if they are contained in this cluster or not if (bSilentTracksUsed) { - KaxTracks & MyTracks = *static_cast(ParentSegment->FindElt(EBML_INFO(KaxTracks))); + const auto& MyTracks = *static_cast(ParentSegment->FindElt(EBML_INFO(KaxTracks))); for (auto&& Trk : MyTracks) { if (EbmlId(*Trk) == EBML_ID(KaxTrackEntry)) { - KaxTrackEntry & entry = *static_cast(Trk); + const auto& entry = *static_cast(Trk); auto tracknum = static_cast(entry.TrackNumber()); for (Index = 0; Index(*Blobs[Index]).TrackNum() == tracknum) @@ -245,7 +245,7 @@ uint64 KaxCluster::GlobalTimecode() const */ int16 KaxCluster::GetBlockLocalTimecode(uint64 aGlobalTimecode) const { - int64 TimecodeDelay = (static_cast(aGlobalTimecode) - static_cast(GlobalTimecode())) / static_cast(GlobalTimecodeScale()); + const int64 TimecodeDelay = (static_cast(aGlobalTimecode) - static_cast(GlobalTimecode())) / static_cast(GlobalTimecodeScale()); assert(TimecodeDelay >= int16(0x8000) && TimecodeDelay <= int16(0x7FFF)); return static_cast(TimecodeDelay); } diff --git a/src/KaxCues.cpp b/src/KaxCues.cpp index 01d1695..9309d04 100644 --- a/src/KaxCues.cpp +++ b/src/KaxCues.cpp @@ -67,8 +67,8 @@ bool KaxCues::AddBlockGroup(const KaxBlockGroup & BlockRef) bool KaxCues::AddBlockBlob(const KaxBlockBlob & BlockReference) { // Do not add the element if it's already present. - bool present = std::any_of(myTempReferences.begin(), myTempReferences.end(), - [&](const KaxBlockBlob *myTempReference) { return myTempReference == &BlockReference; }); + const auto& pr = myTempReferences; + const bool present = std::find(pr.begin(), pr.end(), &BlockReference) != pr.end(); if (present) { return true; } @@ -80,10 +80,10 @@ bool KaxCues::AddBlockBlob(const KaxBlockBlob & BlockReference) void KaxCues::PositionSet(const KaxBlockBlob & BlockReference) { // look for the element in the temporary references - auto it = std::find_if(myTempReferences.begin(), myTempReferences.end(), - [&](const KaxBlockBlob *myTempReference){ return myTempReference == &BlockReference; }); + const auto& pr = myTempReferences; + auto it = std::find(pr.begin(), pr.end(), &BlockReference); - if (it != myTempReferences.end()) { + if (it != pr.end()) { // found, now add the element to the entry list auto & NewPoint = AddNewChild(*this); NewPoint.PositionSet(BlockReference, GlobalTimecodeScale()); @@ -113,7 +113,7 @@ void KaxCues::PositionSet(const KaxBlockGroup & BlockRef) */ const KaxCuePoint * KaxCues::GetTimecodePoint(uint64 aTimecode) const { - uint64 TimecodeToLocate = aTimecode / GlobalTimecodeScale(); + const uint64 TimecodeToLocate = aTimecode / GlobalTimecodeScale(); const KaxCuePoint * aPointPrev = nullptr; uint64 aPrevTime = 0; uint64 aNextTime = EBML_PRETTYLONGINT(0xFFFFFFFFFFFF); diff --git a/src/KaxCuesData.cpp b/src/KaxCuesData.cpp index bc1cded..9c50f3e 100644 --- a/src/KaxCuesData.cpp +++ b/src/KaxCuesData.cpp @@ -158,7 +158,7 @@ bool KaxCuePoint::IsSmallerThan(const EbmlElement * Cmp) const assert(EbmlId(*this) == EBML_ID(KaxCuePoint)); assert(EbmlId(*Cmp) == EBML_ID(KaxCuePoint)); - const KaxCuePoint & theCmp = *static_cast(Cmp); + const auto& theCmp = *static_cast(Cmp); // compare timecode auto TimeCodeA = static_cast(FindElt(EBML_INFO(KaxCueTime))); diff --git a/src/KaxSeekHead.cpp b/src/KaxSeekHead.cpp index d93b041..2b5d911 100644 --- a/src/KaxSeekHead.cpp +++ b/src/KaxSeekHead.cpp @@ -73,7 +73,7 @@ KaxSeek * KaxSeekHead::FindFirstOf(const EbmlCallbacks & Callbacks) const { return (EbmlId(*Elt) == EBML_ID(KaxSeekID)); }); if (it != aElt->end()) { aId = static_cast(*it); - EbmlId aEbmlId(aId->GetBuffer(), aId->GetSize()); + const auto aEbmlId = EbmlId(aId->GetBuffer(), aId->GetSize()); if (aEbmlId == EBML_INFO_ID(Callbacks)) { return aElt; } @@ -122,7 +122,7 @@ bool KaxSeek::IsEbmlId(const EbmlId & aId) const auto _Id = static_cast(FindFirstElt(EBML_INFO(KaxSeekID))); if (_Id == nullptr) return false; - EbmlId aEbmlId(_Id->GetBuffer(), _Id->GetSize()); + const auto aEbmlId = EbmlId(_Id->GetBuffer(), _Id->GetSize()); return (aId == aEbmlId); } @@ -134,8 +134,8 @@ bool KaxSeek::IsEbmlId(const KaxSeek & aPoint) const auto _IdB = static_cast(aPoint.FindFirstElt(EBML_INFO(KaxSeekID))); if (_IdB == nullptr) return false; - EbmlId aEbmlIdA(_IdA->GetBuffer(), _IdA->GetSize()); - EbmlId aEbmlIdB(_IdB->GetBuffer(), _IdB->GetSize()); + const auto aEbmlIdA = EbmlId(_IdA->GetBuffer(), _IdA->GetSize()); + const auto aEbmlIdB = EbmlId(_IdB->GetBuffer(), _IdB->GetSize()); return (aEbmlIdA == aEbmlIdB); }