groupNetworkStats - switch ->at() to []

Test: TreeHugger
Bug: 276296921
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Iecabf1de0d91627f2114ca500b66e0a5019e59e9
diff --git a/service-t/native/libs/libnetworkstats/BpfNetworkStats.cpp b/service-t/native/libs/libnetworkstats/BpfNetworkStats.cpp
index 64a7a98..769ddb3 100644
--- a/service-t/native/libs/libnetworkstats/BpfNetworkStats.cpp
+++ b/service-t/native/libs/libnetworkstats/BpfNetworkStats.cpp
@@ -151,7 +151,7 @@
     // and set, which causes NetworkStats maps wrong item to subtract.
     //
     // Thus, the stats needs to be properly sorted and grouped before reported.
-    groupNetworkStats(lines);
+    groupNetworkStats(*lines);
     return 0;
 }
 
@@ -227,7 +227,7 @@
         return -res.error().code();
     }
 
-    groupNetworkStats(lines);
+    groupNetworkStats(*lines);
     return 0;
 }
 
@@ -237,25 +237,25 @@
     return parseBpfNetworkStatsDevInternal(lines, ifaceStatsMap, ifaceIndexNameMap);
 }
 
-void groupNetworkStats(std::vector<stats_line>* lines) {
-    if (lines->size() <= 1) return;
-    std::sort(lines->begin(), lines->end());
+void groupNetworkStats(std::vector<stats_line>& lines) {
+    if (lines.size() <= 1) return;
+    std::sort(lines.begin(), lines.end());
 
     // Similar to std::unique(), but aggregates the duplicates rather than discarding them.
     size_t currentOutput = 0;
-    for (size_t i = 1; i < lines->size(); i++) {
+    for (size_t i = 1; i < lines.size(); i++) {
         // note that == operator only compares the 'key' portion: iface/uid/tag/set
-        if (lines->at(currentOutput) == lines->at(i)) {
+        if (lines[currentOutput] == lines[i]) {
             // while += operator only affects the 'data' portion: {rx,tx}{Bytes,Packets}
-            lines->at(currentOutput) += lines->at(i);
+            lines[currentOutput] += lines[i];
         } else {
             // okay, we're done aggregating the current line, move to the next one
-            lines->at(++currentOutput) = lines->at(i);
+            lines[++currentOutput] = lines[i];
         }
     }
 
     // possibly shrink the vector - currentOutput is the last line with valid data
-    lines->resize(currentOutput + 1);
+    lines.resize(currentOutput + 1);
 }
 
 // True if lhs equals to rhs, only compare iface, uid, tag and set.
diff --git a/service-t/native/libs/libnetworkstats/include/netdbpf/BpfNetworkStats.h b/service-t/native/libs/libnetworkstats/include/netdbpf/BpfNetworkStats.h
index 1ffa927..5d8ffc3 100644
--- a/service-t/native/libs/libnetworkstats/include/netdbpf/BpfNetworkStats.h
+++ b/service-t/native/libs/libnetworkstats/include/netdbpf/BpfNetworkStats.h
@@ -115,7 +115,7 @@
 int parseBpfNetworkStatsDetail(std::vector<stats_line>* lines);
 
 int parseBpfNetworkStatsDev(std::vector<stats_line>* lines);
-void groupNetworkStats(std::vector<stats_line>* lines);
+void groupNetworkStats(std::vector<stats_line>& lines);
 int cleanStatsMap();
 }  // namespace bpf
 }  // namespace android