merge the Statistic and StatisticBase classes, eliminating virtual methods
authorChris Lattner <sabre@nondot.org>
Wed, 6 Dec 2006 18:20:44 +0000 (18:20 +0000)
committerChris Lattner <sabre@nondot.org>
Wed, 6 Dec 2006 18:20:44 +0000 (18:20 +0000)
and eliminating #includes from the Statistic.h file.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@32282 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/ADT/Statistic.h
lib/Support/Statistic.cpp

index 332a57d1214a9c4e1d249c49b8d54284d88b9766..dd44f2709bedfea154575c5e74d0cf3bd0f6c50f 100644 (file)
 #ifndef LLVM_ADT_STATISTIC_H
 #define LLVM_ADT_STATISTIC_H
 
-#include <ostream>
-#include "llvm/Support/Compiler.h"
-
 namespace llvm {
 
-// StatisticBase - Nontemplated base class for Statistic class...
-class StatisticBase {
+class Statistic {
   const char *Name;
   const char *Desc;
-  static unsigned NumStats;
-protected:
-  StatisticBase(const char *name, const char *desc) : Name(name), Desc(desc) {
-    ++NumStats;  // Keep track of how many stats are created...
-  }
-  // Out of line virtual dtor, to give the vtable etc a home.
-  virtual ~StatisticBase();
-
-  // destroy - Called by subclass dtor so that we can still invoke virtual
-  // functions on the subclass.
-  void destroy() const;
-
-  // printValue - Overridden by template class to print out the value type...
-  virtual void printValue(std::ostream &o) const = 0;
-
-  // hasSomeData - Return true if some data has been aquired.  Avoid printing
-  // lots of zero counts.
-  //
-  virtual bool hasSomeData() const = 0;
-};
-
-// Statistic Class - templated on the data type we are monitoring...
-class Statistic : private StatisticBase {
   unsigned Value;
-
-  virtual void printValue(std::ostream &o) const { o << Value; }
-  virtual bool hasSomeData() const { return Value != 0; }
+  static unsigned NumStats;
 public:
   // Normal constructor, default initialize data item...
   Statistic(const char *name, const char *desc)
-    : StatisticBase(name, desc), Value(0) {}
-
-  // Constructor to provide an initial value...
-  Statistic(const unsigned &Val, const char *name, const char *desc)
-    : StatisticBase(name, desc), Value(Val) {}
+    : Name(name), Desc(desc), Value(0) {
+    ++NumStats;  // Keep track of how many stats are created...
+  }
 
   // Print information when destroyed, iff command line option is specified
-  ~Statistic() { destroy(); }
+  ~Statistic();
 
   // Allow use of this class as the value itself...
   operator unsigned() const { return Value; }
index cd516626361550919e636a7fe24216d529ffa4b6..19cfff33aacbfda9d269e1463f3129152e4f05d1 100644 (file)
@@ -23,6 +23,7 @@
 
 #include "llvm/ADT/Statistic.h"
 #include "llvm/Support/CommandLine.h"
+#include "llvm/ADT/StringExtras.h"
 #include <sstream>
 #include <iostream>
 #include <algorithm>
@@ -31,7 +32,7 @@ using namespace llvm;
 // GetLibSupportInfoOutputFile - Return a file stream to print our output on...
 namespace llvm { extern std::ostream *GetLibSupportInfoOutputFile(); }
 
-unsigned StatisticBase::NumStats = 0;
+unsigned Statistic::NumStats = 0;
 
 // -stats - Command line option to cause transformations to emit stats about
 // what they did.
@@ -61,19 +62,13 @@ struct StatRecord {
 
 static std::vector<StatRecord> *AccumStats = 0;
 
-// Out of line virtual dtor, to give the vtable etc a home.
-StatisticBase::~StatisticBase() {
-}
-
 // Print information when destroyed, iff command line option is specified
-void StatisticBase::destroy() const {
-  if (Enabled && hasSomeData()) {
+Statistic::~Statistic() {
+  if (Enabled && Value != 0) {
     if (AccumStats == 0)
       AccumStats = new std::vector<StatRecord>();
 
-    std::ostringstream Out;
-    printValue(Out);
-    AccumStats->push_back(StatRecord(Out.str(), Name, Desc));
+    AccumStats->push_back(StatRecord(utostr(Value), Name, Desc));
   }
 
   if (--NumStats == 0 && AccumStats) {