]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Reworked cbdata to use std::vector to be able to have a random access iterator
authorFrancesco Chemolli <kinkie@squid-cache.org>
Tue, 11 Feb 2014 12:02:07 +0000 (13:02 +0100)
committerFrancesco Chemolli <kinkie@squid-cache.org>
Tue, 11 Feb 2014 12:02:07 +0000 (13:02 +0100)
src/cbdata.cc

index 74e172448316a7bb0a6dc65d33afaa5c1073e6a4..d9c8d8353bad5ce8188666bde0805bfe12762123 100644 (file)
 #include "cbdata.h"
 #include "mgr/Registration.h"
 #include "Store.h"
-#if USE_CBDATA_DEBUG
-#include "Stack.h"
-#endif
 #include "Generic.h"
 
 #if HAVE_LIMITS_H
 #include <limits.h>
 #endif
+#if USE_CBDATA_DEBUG
+#include <vector>
+#include <algorithm>
+#endif
 
 #if WITH_VALGRIND
 #define HASHED_CBDATA 1
@@ -118,13 +119,13 @@ public:
         if (calls.size() > 1000)
             return;
 
-        calls.push(new CBDataCall(label, aFile, aLine));
+        calls.push_back(new CBDataCall(label, aFile, aLine));
     }
 
     dlink_node link;
     const char *file;
     int line;
-    Stack<CBDataCall*> calls;
+    std::vector<CBDataCall*> calls; // used as a stack with random access operator
 #endif
 
     /* cookie used while debugging */
@@ -211,8 +212,8 @@ cbdata::~cbdata()
 #if USE_CBDATA_DEBUG
 
     while (!calls.empty()) {
-        delete calls.top();
-        calls.pop();
+        delete calls.back();
+        calls.pop_back();
     }
 
 #endif
@@ -317,7 +318,7 @@ cbdataInternalAlloc(cbdata_type type)
 
     c->file = file;
     c->line = line;
-    c->calls = Stack<CBDataCall *> ();
+    c->calls = std::vector<CBDataCall *> ();
     c->addHistory("Alloc", file, line);
     dlinkAdd(c, &c->link, &cbdataEntries);
     debugs(45, 3, "cbdataAlloc: " << p << " " << file << ":" << line);
@@ -615,8 +616,8 @@ CBDATA_CLASS_INIT(generic_cbdata);
 struct CBDataCallDumper : public unary_function<CBDataCall, void> {
     CBDataCallDumper (StoreEntry *anEntry):where(anEntry) {}
 
-    void operator()(CBDataCall const &x) {
-        storeAppendPrintf(where, "%s\t%s\t%d\n", x.label, x.file, x.line);
+    void operator()(CBDataCall const &x) {
+        storeAppendPrintf(where, "%s\t%s\t%d\n", x->label, x->file, x->line);
     }
 
     StoreEntry *where;
@@ -629,7 +630,7 @@ struct CBDataHistoryDumper : public CBDataDumper {
         CBDataDumper::operator()(x);
         storeAppendPrintf(where, "\n");
         storeAppendPrintf(where, "Action\tFile\tLine\n");
-        for_each (x.calls,callDumper);
+        std::for_each (x.calls.begin(), x.calls.end(), callDumper);
         storeAppendPrintf(where, "\n");
     }