@@ -26,11 +26,6 @@ using namespace llvm;
2626// ===----------------------------------------------------------------------===//
2727// GCOVFile implementation.
2828
29- // / ~GCOVFile - Delete GCOVFile and its content.
30- GCOVFile::~GCOVFile () {
31- DeleteContainerPointers (Functions);
32- }
33-
3429// / readGCNO - Read GCNO buffer.
3530bool GCOVFile::readGCNO (GCOVBuffer &Buffer) {
3631 if (!Buffer.readGCNOFormat ()) return false ;
@@ -39,10 +34,10 @@ bool GCOVFile::readGCNO(GCOVBuffer &Buffer) {
3934 if (!Buffer.readInt (Checksum)) return false ;
4035 while (true ) {
4136 if (!Buffer.readFunctionTag ()) break ;
42- GCOVFunction * GFun = new GCOVFunction (*this );
37+ auto GFun = make_unique< GCOVFunction> (*this );
4338 if (!GFun->readGCNO (Buffer, Version))
4439 return false ;
45- Functions.push_back (GFun);
40+ Functions.push_back (std::move ( GFun) );
4641 }
4742
4843 GCNOInitialized = true ;
@@ -97,30 +92,22 @@ bool GCOVFile::readGCDA(GCOVBuffer &Buffer) {
9792
9893// / dump - Dump GCOVFile content to dbgs() for debugging purposes.
9994void GCOVFile::dump () const {
100- for (SmallVectorImpl<GCOVFunction *>::const_iterator I = Functions.begin (),
101- E = Functions.end (); I != E; ++I)
102- (*I)->dump ();
95+ for (const auto &FPtr : Functions)
96+ FPtr->dump ();
10397}
10498
10599// / collectLineCounts - Collect line counts. This must be used after
106100// / reading .gcno and .gcda files.
107101void GCOVFile::collectLineCounts (FileInfo &FI) {
108- for (SmallVectorImpl<GCOVFunction *>::iterator I = Functions.begin (),
109- E = Functions.end (); I != E; ++I)
110- (*I)->collectLineCounts (FI);
102+ for (const auto &FPtr : Functions)
103+ FPtr->collectLineCounts (FI);
111104 FI.setRunCount (RunCount);
112105 FI.setProgramCount (ProgramCount);
113106}
114107
115108// ===----------------------------------------------------------------------===//
116109// GCOVFunction implementation.
117110
118- // / ~GCOVFunction - Delete GCOVFunction and its content.
119- GCOVFunction::~GCOVFunction () {
120- DeleteContainerPointers (Blocks);
121- DeleteContainerPointers (Edges);
122- }
123-
124111// / readGCNO - Read a function from the GCNO buffer. Return false if an error
125112// / occurs.
126113bool GCOVFunction::readGCNO (GCOVBuffer &Buff, GCOV::GCOVVersion Version) {
@@ -150,7 +137,7 @@ bool GCOVFunction::readGCNO(GCOVBuffer &Buff, GCOV::GCOVVersion Version) {
150137 if (!Buff.readInt (BlockCount)) return false ;
151138 for (uint32_t i = 0 , e = BlockCount; i != e; ++i) {
152139 if (!Buff.readInt (Dummy)) return false ; // Block flags;
153- Blocks.push_back (new GCOVBlock (*this , i));
140+ Blocks.push_back (make_unique< GCOVBlock> (*this , i));
154141 }
155142
156143 // read edges.
@@ -168,8 +155,8 @@ bool GCOVFunction::readGCNO(GCOVBuffer &Buff, GCOV::GCOVVersion Version) {
168155 for (uint32_t i = 0 , e = EdgeCount; i != e; ++i) {
169156 uint32_t Dst;
170157 if (!Buff.readInt (Dst)) return false ;
171- GCOVEdge *Edge = new GCOVEdge ( Blocks[BlockNo], Blocks[Dst]);
172- Edges.push_back (Edge );
158+ Edges. push_back (make_unique< GCOVEdge>(* Blocks[BlockNo], * Blocks[Dst]) );
159+ GCOVEdge *Edge = Edges.back (). get ( );
173160 Blocks[BlockNo]->addDstEdge (Edge);
174161 Blocks[Dst]->addSrcEdge (Edge);
175162 if (!Buff.readInt (Dummy)) return false ; // Edge flag
@@ -188,7 +175,7 @@ bool GCOVFunction::readGCNO(GCOVBuffer &Buff, GCOV::GCOVVersion Version) {
188175 << " ).\n " ;
189176 return false ;
190177 }
191- GCOVBlock * Block = Blocks[BlockNo];
178+ GCOVBlock & Block = * Blocks[BlockNo];
192179 if (!Buff.readInt (Dummy)) return false ; // flag
193180 while (Buff.getCursor () != (EndPos - 4 )) {
194181 StringRef F;
@@ -203,7 +190,7 @@ bool GCOVFunction::readGCNO(GCOVBuffer &Buff, GCOV::GCOVVersion Version) {
203190 uint32_t Line;
204191 if (!Buff.readInt (Line)) return false ;
205192 if (!Line) break ;
206- Block-> addLine (Line);
193+ Block. addLine (Line);
207194 }
208195 }
209196 if (!Buff.readInt (Dummy)) return false ; // flag
@@ -300,9 +287,8 @@ uint64_t GCOVFunction::getExitCount() const {
300287// / dump - Dump GCOVFunction content to dbgs() for debugging purposes.
301288void GCOVFunction::dump () const {
302289 dbgs () << " ===== " << Name << " @ " << Filename << " :" << LineNumber << " \n " ;
303- for (SmallVectorImpl<GCOVBlock *>::const_iterator I = Blocks.begin (),
304- E = Blocks.end (); I != E; ++I)
305- (*I)->dump ();
290+ for (const auto &Block : Blocks)
291+ Block->dump ();
306292}
307293
308294// / collectLineCounts - Collect line counts. This must be used after
@@ -313,9 +299,8 @@ void GCOVFunction::collectLineCounts(FileInfo &FI) {
313299 if (LineNumber == 0 )
314300 return ;
315301
316- for (SmallVectorImpl<GCOVBlock *>::iterator I = Blocks.begin (),
317- E = Blocks.end (); I != E; ++I)
318- (*I)->collectLineCounts (FI);
302+ for (const auto &Block : Blocks)
303+ Block->collectLineCounts (FI);
319304 FI.addFunctionLine (Filename, LineNumber, this );
320305}
321306
@@ -335,8 +320,8 @@ void GCOVBlock::addCount(size_t DstEdgeNo, uint64_t N) {
335320 assert (DstEdgeNo < DstEdges.size ()); // up to caller to ensure EdgeNo is valid
336321 DstEdges[DstEdgeNo]->Count = N;
337322 Counter += N;
338- if (!DstEdges[DstEdgeNo]->Dst -> getNumDstEdges ())
339- DstEdges[DstEdgeNo]->Dst -> Counter += N;
323+ if (!DstEdges[DstEdgeNo]->Dst . getNumDstEdges ())
324+ DstEdges[DstEdgeNo]->Dst . Counter += N;
340325}
341326
342327// / sortDstEdges - Sort destination edges by block number, nop if already
@@ -363,15 +348,15 @@ void GCOVBlock::dump() const {
363348 dbgs () << " \t Source Edges : " ;
364349 for (EdgeIterator I = SrcEdges.begin (), E = SrcEdges.end (); I != E; ++I) {
365350 const GCOVEdge *Edge = *I;
366- dbgs () << Edge->Src -> Number << " (" << Edge->Count << " ), " ;
351+ dbgs () << Edge->Src . Number << " (" << Edge->Count << " ), " ;
367352 }
368353 dbgs () << " \n " ;
369354 }
370355 if (!DstEdges.empty ()) {
371356 dbgs () << " \t Destination Edges : " ;
372357 for (EdgeIterator I = DstEdges.begin (), E = DstEdges.end (); I != E; ++I) {
373358 const GCOVEdge *Edge = *I;
374- dbgs () << Edge->Dst -> Number << " (" << Edge->Count << " ), " ;
359+ dbgs () << Edge->Dst . Number << " (" << Edge->Count << " ), " ;
375360 }
376361 dbgs () << " \n " ;
377362 }
@@ -617,8 +602,8 @@ void FileInfo::printFunctionSummary(raw_fd_ostream &OS,
617602 uint32_t BlocksExec = 0 ;
618603 for (GCOVFunction::BlockIterator I = Func->block_begin (),
619604 E = Func->block_end (); I != E; ++I) {
620- const GCOVBlock * Block = *I;
621- if (Block-> getNumDstEdges () && Block-> getCount ())
605+ const GCOVBlock & Block = * *I;
606+ if (Block. getNumDstEdges () && Block. getCount ())
622607 ++BlocksExec;
623608 }
624609
0 commit comments