]> git.ipfire.org Git - thirdparty/squid.git/blobdiff - src/adaptation/History.cc
Source Format Enforcement (#763)
[thirdparty/squid.git] / src / adaptation / History.cc
index d7c9239fd68c13b155360a290ac467ef6f1d34ad..04c5e27a3d74cc897c69a8d60c3abb0ea982f00b 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 1996-2016 The Squid Software Foundation and contributors
+ * Copyright (C) 1996-2021 The Squid Software Foundation and contributors
  *
  * Squid software is distributed under GPLv2+ license and includes
  * contributions from numerous individuals and organizations.
@@ -63,48 +63,37 @@ void Adaptation::History::recordXactFinish(int hid)
     theEntries[hid].stop();
 }
 
-void Adaptation::History::allLogString(const char *serviceId, String &s)
+void Adaptation::History::allLogString(const char *serviceId, SBuf &s)
 {
-    s="";
+    s.clear();
     bool prevWasRetried = false;
-    // XXX: Fix Vector<> so that we can use const_iterator here
-    typedef Adaptation::History::Entries::iterator ECI;
-    for (ECI i = theEntries.begin(); i != theEntries.end(); ++i) {
+    for (auto &i : theEntries) {
         // TODO: here and below, optimize service ID comparison?
-        if (!serviceId || i->service == serviceId) {
-            if (s.size() > 0) // not the first logged time, must delimit
-                s.append(prevWasRetried ? "+" : ",");
-
-            char buf[64];
-            snprintf(buf, sizeof(buf), "%d", i->rptm());
-            s.append(buf);
-
+        if (!serviceId || i.service == serviceId) {
+            if (!s.isEmpty()) // not the first logged time, must delimit
+                s.append(prevWasRetried ? '+' : ',');
+            s.appendf("%d", i.rptm());
             // continue; we may have two identical services (e.g., for retries)
         }
-        prevWasRetried = i->retried;
+        prevWasRetried = i.retried;
     }
 }
 
-void Adaptation::History::sumLogString(const char *serviceId, String &s)
+void Adaptation::History::sumLogString(const char *serviceId, SBuf &s)
 {
-    s="";
+    s.clear();
     int retriedRptm = 0; // sum of rptm times of retried transactions
-    typedef Adaptation::History::Entries::iterator ECI;
-    for (ECI i = theEntries.begin(); i != theEntries.end(); ++i) {
-        if (i->retried) { // do not log retried xact but accumulate their time
-            retriedRptm += i->rptm();
-        } else if (!serviceId || i->service == serviceId) {
-            if (s.size() > 0) // not the first logged time, must delimit
-                s.append(",");
-
-            char buf[64];
-            snprintf(buf, sizeof(buf), "%d", retriedRptm + i->rptm());
-            s.append(buf);
-
+    for (auto & i : theEntries) {
+        if (i.retried) { // do not log retried xact but accumulate their time
+            retriedRptm += i.rptm();
+        } else if (!serviceId || i.service == serviceId) {
+            if (!s.isEmpty()) // not the first logged time, must delimit
+                s.append(',');
+            s.appendf("%d", retriedRptm + i.rptm());
             // continue; we may have two identical services (e.g., for retries)
         }
 
-        if (!i->retried)
+        if (!i.retried)
             retriedRptm = 0;
     }