Commit 73e26d77 authored by Rosen Penev's avatar Rosen Penev Committed by Facebook Github Bot

Use ranged based for loops (#1260)

Summary:
Found with modernize-loop-convert
Signed-off-by: default avatarRosen Penev <rosenp@gmail.com>
Pull Request resolved: https://github.com/facebook/folly/pull/1260

Reviewed By: markisaa

Differential Revision: D18747876

Pulled By: yfeldblum

fbshipit-source-id: f2b19654bb3fcbb75b1210edeef536c88f3052d1
parent db5458a7
...@@ -98,10 +98,10 @@ constexpr poly_table<Deg> make_poly_table() { ...@@ -98,10 +98,10 @@ constexpr poly_table<Deg> make_poly_table() {
for (uint16_t x = 0; x < 256; x++) { for (uint16_t x = 0; x < 256; x++) {
FingerprintPolynomial<Deg> t; FingerprintPolynomial<Deg> t;
t.setHigh8Bits(uint8_t(x)); t.setHigh8Bits(uint8_t(x));
for (int i = 0; i < 8; i++) { for (auto& entry : table) {
t.mulXkmod(8, poly); t.mulXkmod(8, poly);
for (size_t j = 0; j < poly_size(Deg); ++j) { for (size_t j = 0; j < poly_size(Deg); ++j) {
table[i][x][j] = t.get(j); entry[x][j] = t.get(j);
} }
} }
} }
......
...@@ -380,7 +380,7 @@ dynamic::try_get_ptr(json_pointer const& jsonPtr) const& { ...@@ -380,7 +380,7 @@ dynamic::try_get_ptr(json_pointer const& jsonPtr) const& {
size_t curr_idx{0}; size_t curr_idx{0};
StringPiece curr_key{}; StringPiece curr_key{};
for (auto&& it : enumerate(tokens)) { for (auto it : enumerate(tokens)) {
// hit bottom but pointer not exhausted yet // hit bottom but pointer not exhausted yet
if (!curr) { if (!curr) {
return makeUnexpected( return makeUnexpected(
......
...@@ -212,16 +212,14 @@ int AsyncServerSocket::stopAccepting(int shutdownFlags) { ...@@ -212,16 +212,14 @@ int AsyncServerSocket::stopAccepting(int shutdownFlags) {
// removeAcceptCallback(). // removeAcceptCallback().
std::vector<CallbackInfo> callbacksCopy; std::vector<CallbackInfo> callbacksCopy;
callbacks_.swap(callbacksCopy); callbacks_.swap(callbacksCopy);
for (auto it = callbacksCopy.begin(); for (const auto& callback : callbacksCopy) {
it != callbacksCopy.end();
++it) {
// consumer may not be set if we are running in primary event base // consumer may not be set if we are running in primary event base
if (it->consumer) { if (callback.consumer) {
DCHECK(it->eventBase); DCHECK(callback.eventBase);
it->consumer->stop(it->eventBase, it->callback); callback.consumer->stop(callback.eventBase, callback.callback);
} else { } else {
DCHECK(it->callback); DCHECK(callback.callback);
it->callback->acceptStopped(); callback.callback->acceptStopped();
} }
} }
......
...@@ -31,10 +31,8 @@ AsyncSignalHandler::AsyncSignalHandler(EventBase* eventBase) ...@@ -31,10 +31,8 @@ AsyncSignalHandler::AsyncSignalHandler(EventBase* eventBase)
AsyncSignalHandler::~AsyncSignalHandler() { AsyncSignalHandler::~AsyncSignalHandler() {
// Unregister any outstanding events // Unregister any outstanding events
for (auto it = signalEvents_.begin(); for (auto& signalEvent : signalEvents_) {
it != signalEvents_.end(); event_del(&signalEvent.second);
++it) {
event_del(&it->second);
} }
} }
......
...@@ -97,10 +97,8 @@ class ReadCallback : public folly::AsyncTransportWrapper::ReadCallback { ...@@ -97,10 +97,8 @@ class ReadCallback : public folly::AsyncTransportWrapper::ReadCallback {
maxBufferSz(_maxBufferSz) {} maxBufferSz(_maxBufferSz) {}
~ReadCallback() override { ~ReadCallback() override {
for (std::vector<Buffer>::iterator it = buffers.begin(); for (auto& buffer : buffers) {
it != buffers.end(); buffer.free();
++it) {
it->free();
} }
currentBuffer.free(); currentBuffer.free();
} }
......
...@@ -918,15 +918,13 @@ void testConnectOptWrite(size_t size1, size_t size2, bool close = false) { ...@@ -918,15 +918,13 @@ void testConnectOptWrite(size_t size1, size_t size2, bool close = false) {
// Make sure the read callback received all of the data // Make sure the read callback received all of the data
size_t bytesRead = 0; size_t bytesRead = 0;
for (vector<ReadCallback::Buffer>::const_iterator it = rcb.buffers.begin(); for (const auto& buffer : rcb.buffers) {
it != rcb.buffers.end();
++it) {
size_t start = bytesRead; size_t start = bytesRead;
bytesRead += it->length; bytesRead += buffer.length;
size_t end = bytesRead; size_t end = bytesRead;
if (start < size1) { if (start < size1) {
size_t cmpLen = min(size1, end) - start; size_t cmpLen = min(size1, end) - start;
ASSERT_EQ(memcmp(it->buffer, buf1.get() + start, cmpLen), 0); ASSERT_EQ(memcmp(buffer.buffer, buf1.get() + start, cmpLen), 0);
} }
if (end > size1 && end <= size1 + size2) { if (end > size1 && end <= size1 + size2) {
size_t itOffset; size_t itOffset;
...@@ -942,7 +940,7 @@ void testConnectOptWrite(size_t size1, size_t size2, bool close = false) { ...@@ -942,7 +940,7 @@ void testConnectOptWrite(size_t size1, size_t size2, bool close = false) {
cmpLen = end - size1; cmpLen = end - size1;
} }
ASSERT_EQ( ASSERT_EQ(
memcmp(it->buffer + itOffset, buf2.get() + buf2Offset, cmpLen), 0); memcmp(buffer.buffer + itOffset, buf2.get() + buf2Offset, cmpLen), 0);
} }
} }
ASSERT_EQ(bytesRead, size1 + size2); ASSERT_EQ(bytesRead, size1 + size2);
...@@ -1509,10 +1507,8 @@ TEST(AsyncSocketTest, ClosePendingWritesWhileClosing) { ...@@ -1509,10 +1507,8 @@ TEST(AsyncSocketTest, ClosePendingWritesWhileClosing) {
socket->closeNow(); socket->closeNow();
// Make sure writeError() was invoked on all of the pending write callbacks // Make sure writeError() was invoked on all of the pending write callbacks
for (WriteCallbackVector::const_iterator it = writeCallbacks.begin(); for (const auto& writeCallback : writeCallbacks) {
it != writeCallbacks.end(); ASSERT_EQ((writeCallback)->state, STATE_FAILED);
++it) {
ASSERT_EQ((*it)->state, STATE_FAILED);
} }
ASSERT_TRUE(socket->isClosedBySelf()); ASSERT_TRUE(socket->isClosedBySelf());
......
...@@ -1300,11 +1300,9 @@ TYPED_TEST_P(EventBaseTest, RunInThread) { ...@@ -1300,11 +1300,9 @@ TYPED_TEST_P(EventBaseTest, RunInThread) {
for (uint32_t n = 0; n < numThreads; ++n) { for (uint32_t n = 0; n < numThreads; ++n) {
expectedValues[n] = 0; expectedValues[n] = 0;
} }
for (std::deque<std::pair<int, int>>::const_iterator it = data.values.begin(); for (const auto& dataValue : data.values) {
it != data.values.end(); int threadID = dataValue.first;
++it) { int value = dataValue.second;
int threadID = it->first;
int value = it->second;
ASSERT_EQ(expectedValues[threadID], value); ASSERT_EQ(expectedValues[threadID], value);
++expectedValues[threadID]; ++expectedValues[threadID];
} }
......
...@@ -243,7 +243,7 @@ json_patch::apply(dynamic& obj) { ...@@ -243,7 +243,7 @@ json_patch::apply(dynamic& obj) {
using error_code = patch_application_error_code; using error_code = patch_application_error_code;
using error = patch_application_error; using error = patch_application_error;
for (auto&& it : enumerate(ops_)) { for (auto it : enumerate(ops_)) {
auto const index = it.index; auto const index = it.index;
auto const& op = *it; auto const& op = *it;
auto resolved_path = obj.try_get_ptr(op.path); auto resolved_path = obj.try_get_ptr(op.path);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment