]> granicus.if.org Git - libmatroska/commitdiff
clang-tidy: add const
authorRosen Penev <rosenp@gmail.com>
Sat, 24 Sep 2022 21:21:07 +0000 (14:21 -0700)
committerRosen Penev <rosenp@gmail.com>
Mon, 26 Sep 2022 20:48:33 +0000 (13:48 -0700)
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 <rosenp@gmail.com>
src/KaxBlock.cpp
src/KaxCluster.cpp
src/KaxCues.cpp
src/KaxCuesData.cpp
src/KaxSeekHead.cpp

index 417e4d16a27543501388baa538a8288883c6c5b8..4d069ded4af1ae648905b20568f24bd5b703a118 100644 (file)
@@ -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<int16>(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<KaxReferenceBlock>(*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<KaxReferenceBlock>(*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<KaxReferenceBlock>(*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<KaxBlock *>(this->FindElt(EBML_INFO(KaxBlock)));
+  const auto& MyBlock = *static_cast<KaxBlock *>(this->FindElt(EBML_INFO(KaxBlock)));
   return MyBlock.GlobalTimecode();
 
 }
 
 uint16 KaxBlockGroup::TrackNumber() const
 {
-  KaxInternalBlock & MyBlock = *static_cast<KaxBlock *>(this->FindElt(EBML_INFO(KaxBlock)));
+  const auto& MyBlock = *static_cast<KaxBlock *>(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<KaxBlock *>(this->FindElt(EBML_INFO(KaxBlock)));
+  auto& MyBlock = *static_cast<KaxBlock *>(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<KaxBlockDuration *>(FindFirstElt(EBML_INFO(KaxBlockDuration), true));
+  const int64 scale = ParentTrack->GlobalTimecodeScale();
+  auto& myDuration = *static_cast<KaxBlockDuration *>(FindFirstElt(EBML_INFO(KaxBlockDuration), true));
   *(static_cast<EbmlUInteger *>(&myDuration)) = TimeLength / static_cast<uint64>(scale);
 }
 
index 8903902fc7b88265587765a0bf2ba26623d38443..a2adaff4750f9b330fbfaa10a262d3786ae0a0cf 100644 (file)
@@ -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<KaxTracks *>(ParentSegment->FindElt(EBML_INFO(KaxTracks)));
+      const auto& MyTracks = *static_cast<KaxTracks *>(ParentSegment->FindElt(EBML_INFO(KaxTracks)));
       for (auto&& Trk : MyTracks) {
         if (EbmlId(*Trk) == EBML_ID(KaxTrackEntry)) {
-          KaxTrackEntry & entry = *static_cast<KaxTrackEntry *>(Trk);
+          const auto& entry = *static_cast<KaxTrackEntry *>(Trk);
           auto tracknum = static_cast<uint32>(entry.TrackNumber());
           auto track = std::find_if(ElementList.begin(), ElementList.end(), [=](EbmlElement *element)
               { return EbmlId(*element) == EBML_ID(KaxBlockGroup) && static_cast<KaxBlockGroup *>(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<KaxTracks *>(ParentSegment->FindElt(EBML_INFO(KaxTracks)));
+      const auto& MyTracks = *static_cast<KaxTracks *>(ParentSegment->FindElt(EBML_INFO(KaxTracks)));
       for (auto&& Trk : MyTracks) {
         if (EbmlId(*Trk) == EBML_ID(KaxTrackEntry)) {
-          KaxTrackEntry & entry = *static_cast<KaxTrackEntry *>(Trk);
+          const auto& entry = *static_cast<KaxTrackEntry *>(Trk);
           auto tracknum = static_cast<uint32>(entry.TrackNumber());
           for (Index = 0; Index<Blobs.size(); Index++) {
             if (static_cast<KaxInternalBlock&>(*Blobs[Index]).TrackNum() == tracknum)
@@ -245,7 +245,7 @@ uint64 KaxCluster::GlobalTimecode() const
 */
 int16 KaxCluster::GetBlockLocalTimecode(uint64 aGlobalTimecode) const
 {
-  int64 TimecodeDelay = (static_cast<int64>(aGlobalTimecode) - static_cast<int64>(GlobalTimecode())) / static_cast<int64>(GlobalTimecodeScale());
+  const int64 TimecodeDelay = (static_cast<int64>(aGlobalTimecode) - static_cast<int64>(GlobalTimecode())) / static_cast<int64>(GlobalTimecodeScale());
   assert(TimecodeDelay >= int16(0x8000) && TimecodeDelay <= int16(0x7FFF));
   return static_cast<int16>(TimecodeDelay);
 }
index 01d169513bc355d13ed17d610ba98a83118c4efd..9309d04e378252f723c68da4b4cb2a3fcf1f2f2b 100644 (file)
@@ -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<KaxCuePoint>(*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);
index bc1cded885e2a48411ac541612378b9430e11854..9c50f3ee7564f1702dab5a81b32ce4a644c84781 100644 (file)
@@ -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<const KaxCuePoint *>(Cmp);
+  const auto& theCmp = *static_cast<const KaxCuePoint *>(Cmp);
 
   // compare timecode
   auto TimeCodeA = static_cast<const KaxCueTime *>(FindElt(EBML_INFO(KaxCueTime)));
index d93b0417c0e66410406b38d2b249bffd07f3630a..2b5d9114a5757743fa47a00981146b2c7b28ed2a 100644 (file)
@@ -73,7 +73,7 @@ KaxSeek * KaxSeekHead::FindFirstOf(const EbmlCallbacks & Callbacks) const
       { return (EbmlId(*Elt) == EBML_ID(KaxSeekID)); });
     if (it != aElt->end()) {
       aId = static_cast<KaxSeekID*>(*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<KaxSeekID*>(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<KaxSeekID*>(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);
 }