From 0066f9290e95dddedc47472e927319893929b05b Mon Sep 17 00:00:00 2001 From: Devang Patel Date: Thu, 29 Sep 2011 17:06:40 +0000 Subject: Simplify. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@140789 91177308-0d34-0410-b5e6-96231b3b80d8 --- tools/llvm-cov/GCOVReader.cpp | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) (limited to 'tools') diff --git a/tools/llvm-cov/GCOVReader.cpp b/tools/llvm-cov/GCOVReader.cpp index e4570b1229..2b40a84f8e 100644 --- a/tools/llvm-cov/GCOVReader.cpp +++ b/tools/llvm-cov/GCOVReader.cpp @@ -27,6 +27,16 @@ GCOVFile::~GCOVFile() { DeleteContainerPointers(Functions); } +/// isGCDAFile - Return true if Format identifies a .gcda file. +static bool isGCDAFile(GCOVFormat Format) { + return Format == GCDA_402 || Format == GCDA_404; +} + +/// isGCNOFile - Return true if Format identifies a .gcno file. +static bool isGCNOFile(GCOVFormat Format) { + return Format == GCNO_402 || Format == GCNO_404; +} + /// read - Read GCOV buffer. bool GCOVFile::read(GCOVBuffer &Buffer) { GCOVFormat Format = Buffer.readGCOVFormat(); @@ -36,20 +46,16 @@ bool GCOVFile::read(GCOVBuffer &Buffer) { unsigned i = 0; while (1) { GCOVFunction *GFun = NULL; - if (Format == GCDA_402 || Format == GCDA_404) { - if (i < Functions.size()) - GFun = Functions[i]; - } else + if (isGCDAFile(Format)) { + // Use existing function while reading .gcda file. + assert (i < Functions.size() && ".gcda data does not match .gcno data"); + GFun = Functions[i]; + } else if (isGCNOFile(Format)){ GFun = new GCOVFunction(); - - if (GFun && GFun->read(Buffer, Format)) { - if (Format == GCNO_402 || Format == GCNO_404) - Functions.push_back(GFun); + Functions.push_back(GFun); } - else { - delete GFun; + if (!GFun || !GFun->read(Buffer, Format)) break; - } ++i; } return true; -- cgit v1.2.3