Bug 1302401 - This check converts for(...; ...; ...) loops to use the new range-based loops in C++11. r=Waldo
authorSylvestre Ledru <sledru@mozilla.com>
Tue, 27 Sep 2016 15:20:44 +0200
changeset 315768 9c1d4bb7c4ee3b75b5a2c08f5bd1a213320ff335
parent 315767 3d533ce7453235cb8796d7b3bef70a44b89ba0d3
child 315769 d19b41ff1f18b530145742b0d11abbd482082f86
push id20634
push usercbook@mozilla.com
push dateFri, 30 Sep 2016 10:10:13 +0000
treeherderfx-team@afe79b010d13 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersWaldo
bugs1302401
milestone52.0a1
Bug 1302401 - This check converts for(...; ...; ...) loops to use the new range-based loops in C++11. r=Waldo MozReview-Commit-ID: LMvVDStstPx
js/src/perf/pm_linux.cpp
--- a/js/src/perf/pm_linux.cpp
+++ b/js/src/perf/pm_linux.cpp
@@ -116,18 +116,18 @@ Impl::Impl()
 {
 }
 
 Impl::~Impl()
 {
     // Close all active counter descriptors.  Take care to do the group
     // leader last (this may not be necessary, but it's unclear what
     // happens if you close the group leader out from under a group).
-    for (int i = 0; i < PerfMeasurement::NUM_MEASURABLE_EVENTS; i++) {
-        int fd = this->*(kSlots[i].fd);
+    for (const auto& slot : kSlots) {
+        int fd = this->*(slot.fd);
         if (fd != -1 && fd != group_leader)
             close(fd);
     }
 
     if (group_leader != -1)
         close(group_leader);
 }
 
@@ -135,28 +135,28 @@ EventMask
 Impl::init(EventMask toMeasure)
 {
     MOZ_ASSERT(group_leader == -1);
     if (!toMeasure)
         return EventMask(0);
 
     EventMask measured = EventMask(0);
     struct perf_event_attr attr;
-    for (int i = 0; i < PerfMeasurement::NUM_MEASURABLE_EVENTS; i++) {
-        if (!(toMeasure & kSlots[i].bit))
+    for (const auto& slot : kSlots) {
+        if (!(toMeasure & slot.bit))
             continue;
 
         memset(&attr, 0, sizeof(attr));
         attr.size = sizeof(attr);
 
         // Set the type and config fields to indicate the counter we
         // want to enable.  We want read format 0, and we're not using
         // sampling, so leave those fields unset.
-        attr.type = kSlots[i].type;
-        attr.config = kSlots[i].config;
+        attr.type = slot.type;
+        attr.config = slot.config;
 
         // If this will be the group leader it should start off
         // disabled.  Otherwise it should start off enabled (but blocked
         // on the group leader).
         if (group_leader == -1)
             attr.disabled = 1;
 
         // The rest of the bit fields are really poorly documented.
@@ -170,18 +170,18 @@ Impl::init(EventMask toMeasure)
         int fd = sys_perf_event_open(&attr,
                                      0 /* trace self */,
                                      -1 /* on any cpu */,
                                      group_leader,
                                      0 /* no flags presently defined */);
         if (fd == -1)
             continue;
 
-        measured = EventMask(measured | kSlots[i].bit);
-        this->*(kSlots[i].fd) = fd;
+        measured = EventMask(measured | slot.bit);
+        this->*(slot.fd) = fd;
         if (group_leader == -1)
             group_leader = fd;
     }
     return measured;
 }
 
 void
 Impl::start()
@@ -202,25 +202,25 @@ Impl::stop(PerfMeasurement* counters)
 
     if (!running || group_leader == -1)
         return;
 
     ioctl(group_leader, PERF_EVENT_IOC_DISABLE, 0);
     running = false;
 
     // read out and reset all the counter values
-    for (int i = 0; i < PerfMeasurement::NUM_MEASURABLE_EVENTS; i++) {
-        int fd = this->*(kSlots[i].fd);
+    for (const auto& slot : kSlots) {
+        int fd = this->*(slot.fd);
         if (fd == -1)
             continue;
 
         if (read(fd, buf, sizeof(buf)) == sizeof(uint64_t)) {
             uint64_t cur;
             memcpy(&cur, buf, sizeof(uint64_t));
-            counters->*(kSlots[i].counter) += cur;
+            counters->*(slot.counter) += cur;
         }
 
         // Reset the counter regardless of whether the read did what
         // we expected.
         ioctl(fd, PERF_EVENT_IOC_RESET, 0);
     }
 }
 
@@ -268,21 +268,21 @@ PerfMeasurement::stop()
 {
     if (impl)
         static_cast<Impl*>(impl)->stop(this);
 }
 
 void
 PerfMeasurement::reset()
 {
-    for (int i = 0; i < NUM_MEASURABLE_EVENTS; i++) {
-        if (eventsMeasured & kSlots[i].bit)
-            this->*(kSlots[i].counter) = 0;
+    for (const auto& slot : kSlots) {
+        if (eventsMeasured & slot.bit)
+            this->*(slot.counter) = 0;
         else
-            this->*(kSlots[i].counter) = -1;
+            this->*(slot.counter) = -1;
     }
 }
 
 bool
 PerfMeasurement::canMeasureSomething()
 {
     // Find out if the kernel implements the performance measurement
     // API.  If it doesn't, syscall(__NR_perf_event_open, ...) is