kudu-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From t...@apache.org
Subject [1/3] incubator-kudu git commit: Convert collection iteration to c++11 foreach
Date Fri, 22 Jan 2016 02:32:46 GMT
Repository: incubator-kudu
Updated Branches:
  refs/heads/master 113d5b092 -> 8260093b9


Convert collection iteration to c++11 foreach

This patch was created using the clang-modernize tool with a few manual
tweaks.

Change-Id: Ie81b207672e9da628da95630e22dc73811740589
Reviewed-on: http://gerrit.cloudera.org:8080/1799
Tested-by: Internal Jenkins
Reviewed-by: Todd Lipcon <todd@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/incubator-kudu/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-kudu/commit/47d69dd6
Tree: http://git-wip-us.apache.org/repos/asf/incubator-kudu/tree/47d69dd6
Diff: http://git-wip-us.apache.org/repos/asf/incubator-kudu/diff/47d69dd6

Branch: refs/heads/master
Commit: 47d69dd6e66e61966ec83a44e3f25d90c9ed60cc
Parents: 113d5b0
Author: Dan Burkert <dan@cloudera.com>
Authored: Tue Jan 19 18:20:17 2016 -0800
Committer: Todd Lipcon <todd@apache.org>
Committed: Fri Jan 22 01:26:08 2016 +0000

----------------------------------------------------------------------
 src/kudu/benchmarks/tpch/tpch1.cc               | 15 +++---
 src/kudu/codegen/module_builder.cc              |  4 +-
 src/kudu/common/id_mapping.h                    | 10 ++--
 src/kudu/common/partition.cc                    |  2 +-
 src/kudu/common/row.h                           | 11 +---
 src/kudu/common/schema.cc                       |  4 +-
 src/kudu/consensus/log_anchor_registry-test.cc  |  8 +--
 src/kudu/consensus/log_anchor_registry.cc       |  4 +-
 src/kudu/consensus/log_cache.cc                 |  8 +--
 src/kudu/consensus/log_util.cc                  |  5 +-
 src/kudu/consensus/raft_consensus_state.cc      |  7 ++-
 src/kudu/gutil/charmap.h                        |  4 +-
 src/kudu/gutil/map-util.h                       |  5 +-
 src/kudu/gutil/strings/escaping.cc              | 13 +++--
 src/kudu/gutil/strings/join.cc                  | 14 +++---
 src/kudu/gutil/strings/serialize.cc             | 45 ++++++++---------
 src/kudu/gutil/strings/split.cc                 |  8 +--
 src/kudu/gutil/strings/split.h                  |  4 +-
 src/kudu/gutil/strings/split_internal.h         |  4 +-
 src/kudu/gutil/strings/strip.cc                 |  6 +--
 src/kudu/gutil/strings/util.cc                  |  4 +-
 .../alter_table-randomized-test.cc              |  8 +--
 src/kudu/integration-tests/mini_cluster.cc      |  4 +-
 src/kudu/rpc/mt-rpc-test.cc                     |  8 +--
 .../tablet/mt-rowset_delta_compaction-test.cc   | 16 +++---
 src/kudu/tablet/mvcc.cc                         |  6 +--
 src/kudu/tablet/tablet-test-util.h              |  4 +-
 src/kudu/util/auto_release_pool.h               |  5 +-
 src/kudu/util/blocking_queue-test.cc            |  5 +-
 src/kudu/util/debug/trace_event_impl.cc         | 53 +++++++++-----------
 src/kudu/util/mem_tracker.cc                    | 32 ++++++------
 src/kudu/util/memenv/memenv.cc                  |  4 +-
 src/kudu/util/rle-test.cc                       |  8 +--
 src/kudu/util/string_case.cc                    |  7 ++-
 34 files changed, 158 insertions(+), 187 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-kudu/blob/47d69dd6/src/kudu/benchmarks/tpch/tpch1.cc
----------------------------------------------------------------------
diff --git a/src/kudu/benchmarks/tpch/tpch1.cc b/src/kudu/benchmarks/tpch/tpch1.cc
index f96f56b..73fb295 100644
--- a/src/kudu/benchmarks/tpch/tpch1.cc
+++ b/src/kudu/benchmarks/tpch/tpch1.cc
@@ -205,13 +205,12 @@ void Tpch1(RpcLineItemDAO *dao) {
     }
   }
   LOG(INFO) << "Result: ";
-  for (slice_map_map::iterator ii = results.begin();
-       ii != results.end(); ++ii) {
-    const SliceMapKey returnflag = ii->first;
-    slice_map *maps = ii->second;
-    for (slice_map::iterator jj = maps->begin(); jj != maps->end(); ++jj) {
-      const SliceMapKey linestatus = jj->first;
-      Result *r = jj->second;
+  for (const auto& result : results) {
+    const SliceMapKey returnflag = result.first;
+    const auto* maps = result.second;
+    for (const auto& map : *maps) {
+      const SliceMapKey linestatus = map.first;
+      Result* r = map.second;
       double avg_q = static_cast<double>(r->l_quantity) / r->count;
       double avg_ext_p = r->l_extendedprice / r->count;
       double avg_discount = r->l_discount / r->count;
@@ -219,7 +218,7 @@ void Tpch1(RpcLineItemDAO *dao) {
                    linestatus.slice.ToString() << ", " <<
                    r->l_quantity << ", " <<
                    StringPrintf("%.2f", r->l_extendedprice) << ", " <<
-                   // TODO those two are missing at the moment, might want to chagne Result
+                   // TODO those two are missing at the moment, might want to change Result
                    // sum(l_extendedprice * (1 - l_discount))
                    // sum(l_extendedprice * (1 - l_discount) * (1 + l_tax))
                    StringPrintf("%.2f", avg_q) << ", " <<

http://git-wip-us.apache.org/repos/asf/incubator-kudu/blob/47d69dd6/src/kudu/codegen/module_builder.cc
----------------------------------------------------------------------
diff --git a/src/kudu/codegen/module_builder.cc b/src/kudu/codegen/module_builder.cc
index 533f238..f43f439 100644
--- a/src/kudu/codegen/module_builder.cc
+++ b/src/kudu/codegen/module_builder.cc
@@ -110,8 +110,8 @@ string ToString(const Function* f) {
 }
 
 bool ModuleContains(const Module& m, const Function* fptr) {
-  for (Module::const_iterator it = m.begin(); it != m.end(); ++it) {
-    if (&*it == fptr) return true;
+  for (const auto& function : m) {
+    if (&function == fptr) return true;
   }
   return false;
 }

http://git-wip-us.apache.org/repos/asf/incubator-kudu/blob/47d69dd6/src/kudu/common/id_mapping.h
----------------------------------------------------------------------
diff --git a/src/kudu/common/id_mapping.h b/src/kudu/common/id_mapping.h
index 624201b..d7ef9d5 100644
--- a/src/kudu/common/id_mapping.h
+++ b/src/kudu/common/id_mapping.h
@@ -145,16 +145,16 @@ class IdMapping {
     mask_ = new_capacity - 1;
     entries.swap(entries_);
 
-    for (int i = 0; i < entries.size(); i++) {
-      if (entries[i].first != kNoEntry) {
-        set(entries[i].first, entries[i].second);
+    for (const auto& entry : entries) {
+      if (entry.first != kNoEntry) {
+        set(entry.first, entry.second);
       }
     }
   }
 
   static void ClearMap(std::vector<value_type>* v) {
-    for (int i = 0; i < v->size(); i++) {
-      (*v)[i] = std::make_pair(kNoEntry, kNoEntry);
+    for (auto& entry : *v) {
+      entry = std::make_pair(kNoEntry, kNoEntry);
     }
   }
 

http://git-wip-us.apache.org/repos/asf/incubator-kudu/blob/47d69dd6/src/kudu/common/partition.cc
----------------------------------------------------------------------
diff --git a/src/kudu/common/partition.cc b/src/kudu/common/partition.cc
index 14de73e..4ce5e5d 100644
--- a/src/kudu/common/partition.cc
+++ b/src/kudu/common/partition.cc
@@ -407,7 +407,7 @@ Status PartitionSchema::DecodeHashBuckets(Slice* encoded_key,
         Substitute("expected encoded hash key to be at least $0 bytes (only found $1)",
                    hash_components_size, encoded_key->size()));
   }
-  for (int i = 0; i < hash_bucket_schemas_.size(); i++) {
+  for (const auto& schema : hash_bucket_schemas_) {
     uint32_t big_endian;
     memcpy(&big_endian, encoded_key->data(), sizeof(uint32_t));
     buckets->push_back(BigEndian::ToHost32(big_endian));

http://git-wip-us.apache.org/repos/asf/incubator-kudu/blob/47d69dd6/src/kudu/common/row.h
----------------------------------------------------------------------
diff --git a/src/kudu/common/row.h b/src/kudu/common/row.h
index a501274..655dbc3 100644
--- a/src/kudu/common/row.h
+++ b/src/kudu/common/row.h
@@ -234,11 +234,7 @@ class RowProjector {
     DCHECK_SCHEMA_EQ(*projection_, *dst_row->schema());
 
     // Copy directly from base Data
-    for (vector<ProjectionIdxMapping>::const_iterator it =
-           base_cols_mapping_.begin();
-         it != base_cols_mapping_.end();
-         ++it) {
-      const ProjectionIdxMapping& base_mapping = *it;
+    for (const auto& base_mapping : base_cols_mapping_) {
       typename RowType1::Cell src_cell = src_row.cell(base_mapping.second);
       typename RowType2::Cell dst_cell = dst_row->cell(base_mapping.first);
       RETURN_NOT_OK(CopyCell(src_cell, &dst_cell, dst_arena));
@@ -248,10 +244,7 @@ class RowProjector {
     DCHECK(adapter_cols_mapping_.size() == 0) << "Value Adapter not supported yet";
 
     // Fill with Defaults
-    for (vector<size_t>::const_iterator it = projection_defaults_.begin();
-         it != projection_defaults_.end();
-         ++it) {
-      size_t proj_idx = *it;
+    for (auto proj_idx : projection_defaults_) {
       const ColumnSchema& col_proj = projection_->column(proj_idx);
       const void *vdefault = FOR_READ ? col_proj.read_default_value() :
                                         col_proj.write_default_value();

http://git-wip-us.apache.org/repos/asf/incubator-kudu/blob/47d69dd6/src/kudu/common/schema.cc
----------------------------------------------------------------------
diff --git a/src/kudu/common/schema.cc b/src/kudu/common/schema.cc
index 0f16ffb..bd83088 100644
--- a/src/kudu/common/schema.cc
+++ b/src/kudu/common/schema.cc
@@ -388,8 +388,8 @@ void SchemaBuilder::Reset(const Schema& schema) {
   cols_ = schema.cols_;
   col_ids_ = schema.col_ids_;
   num_key_columns_ = schema.num_key_columns_;
-  for (int i = 0; i < cols_.size(); ++i) {
-    col_names_.insert(cols_[i].name());
+  for (const auto& column : cols_) {
+    col_names_.insert(column.name());
   }
 
   if (col_ids_.empty()) {

http://git-wip-us.apache.org/repos/asf/incubator-kudu/blob/47d69dd6/src/kudu/consensus/log_anchor_registry-test.cc
----------------------------------------------------------------------
diff --git a/src/kudu/consensus/log_anchor_registry-test.cc b/src/kudu/consensus/log_anchor_registry-test.cc
index db2c394..817fe0b 100644
--- a/src/kudu/consensus/log_anchor_registry-test.cc
+++ b/src/kudu/consensus/log_anchor_registry-test.cc
@@ -54,8 +54,8 @@ TEST_F(LogAnchorRegistryTest, TestDuplicateInserts) {
   // Register a bunch of anchors at log index 1.
   const int num_anchors = 10;
   LogAnchor anchors[num_anchors];
-  for (int i = 0; i < num_anchors; i++) {
-    reg->Register(1, test_name, &anchors[i]);
+  for (auto& anchor : anchors) {
+    reg->Register(1, test_name, &anchor);
   }
 
   // We should see index 1 as the earliest registered.
@@ -64,8 +64,8 @@ TEST_F(LogAnchorRegistryTest, TestDuplicateInserts) {
   ASSERT_EQ(1, first_index);
 
   // Unregister them all.
-  for (int i = 0; i < num_anchors; i++) {
-    ASSERT_OK(reg->Unregister(&anchors[i]));
+  for (auto& anchor : anchors) {
+    ASSERT_OK(reg->Unregister(&anchor));
   }
 
   // We should see none registered.

http://git-wip-us.apache.org/repos/asf/incubator-kudu/blob/47d69dd6/src/kudu/consensus/log_anchor_registry.cc
----------------------------------------------------------------------
diff --git a/src/kudu/consensus/log_anchor_registry.cc b/src/kudu/consensus/log_anchor_registry.cc
index f858617..0ad9a7d 100644
--- a/src/kudu/consensus/log_anchor_registry.cc
+++ b/src/kudu/consensus/log_anchor_registry.cc
@@ -40,8 +40,8 @@ LogAnchorRegistry::~LogAnchorRegistry() {
 }
 
 void LogAnchorRegistry::Register(int64_t log_index,
-                                  const string& owner,
-                                  LogAnchor* anchor) {
+                                 const string& owner,
+                                 LogAnchor* anchor) {
   boost::lock_guard<simple_spinlock> l(lock_);
   RegisterUnlocked(log_index, owner, anchor);
 }

http://git-wip-us.apache.org/repos/asf/incubator-kudu/blob/47d69dd6/src/kudu/consensus/log_cache.cc
----------------------------------------------------------------------
diff --git a/src/kudu/consensus/log_cache.cc b/src/kudu/consensus/log_cache.cc
index 26358df..3700357 100644
--- a/src/kudu/consensus/log_cache.cc
+++ b/src/kudu/consensus/log_cache.cc
@@ -145,8 +145,8 @@ Status LogCache::AppendOperations(const vector<ReplicateRefPtr>& msgs,
 
 
   int64_t mem_required = 0;
-  for (int i = 0; i < msgs.size(); i++) {
-    mem_required += msgs[i]->get()->SpaceUsed();
+  for (const auto& msg : msgs) {
+    mem_required += msg->get()->SpaceUsed();
   }
 
   // Try to consume the memory. If it can't be consumed, we may need to evict.
@@ -173,8 +173,8 @@ Status LogCache::AppendOperations(const vector<ReplicateRefPtr>& msgs,
     borrowed_memory = parent_tracker_->LimitExceeded();
   }
 
-  for (int i = 0; i < msgs.size(); i++) {
-    InsertOrDie(&cache_,  msgs[i]->get()->id().index(), msgs[i]);
+  for (const auto& msg : msgs) {
+    InsertOrDie(&cache_,  msg->get()->id().index(), msg);
   }
 
   // We drop the lock during the AsyncAppendReplicates call, since it may block

http://git-wip-us.apache.org/repos/asf/incubator-kudu/blob/47d69dd6/src/kudu/consensus/log_util.cc
----------------------------------------------------------------------
diff --git a/src/kudu/consensus/log_util.cc b/src/kudu/consensus/log_util.cc
index 5e79bfd..f699be0 100644
--- a/src/kudu/consensus/log_util.cc
+++ b/src/kudu/consensus/log_util.cc
@@ -777,11 +777,10 @@ void CreateBatchFromAllocatedOperations(const vector<consensus::ReplicateRefPtr>
                                         gscoped_ptr<LogEntryBatchPB>* batch) {
   gscoped_ptr<LogEntryBatchPB> entry_batch(new LogEntryBatchPB);
   entry_batch->mutable_entry()->Reserve(msgs.size());
-  for (size_t i = 0; i < msgs.size(); i++) {
-    consensus::ReplicateMsg* msg = msgs[i]->get();
+  for (const auto& msg : msgs) {
     LogEntryPB* entry_pb = entry_batch->add_entry();
     entry_pb->set_type(log::REPLICATE);
-    entry_pb->set_allocated_replicate(msg);
+    entry_pb->set_allocated_replicate(msg->get());
   }
   batch->reset(entry_batch.release());
 }

http://git-wip-us.apache.org/repos/asf/incubator-kudu/blob/47d69dd6/src/kudu/consensus/raft_consensus_state.cc
----------------------------------------------------------------------
diff --git a/src/kudu/consensus/raft_consensus_state.cc b/src/kudu/consensus/raft_consensus_state.cc
index 52659b2..6a2c34e 100644
--- a/src/kudu/consensus/raft_consensus_state.cc
+++ b/src/kudu/consensus/raft_consensus_state.cc
@@ -372,12 +372,11 @@ Status ReplicaState::CancelPendingTransactions() {
 
     LOG_WITH_PREFIX_UNLOCKED(INFO) << "Trying to abort " << pending_txns_.size()
                                    << " pending transactions.";
-    for (IndexToRoundMap::iterator iter = pending_txns_.begin();
-         iter != pending_txns_.end(); iter++) {
-      const scoped_refptr<ConsensusRound>& round = (*iter).second;
+    for (const auto& txn : pending_txns_) {
+      const scoped_refptr<ConsensusRound>& round = txn.second;
       // We cancel only transactions whose applies have not yet been triggered.
       LOG_WITH_PREFIX_UNLOCKED(INFO) << "Aborting transaction as it isn't in flight: "
-                            << (*iter).second->replicate_msg()->ShortDebugString();
+                            << txn.second->replicate_msg()->ShortDebugString();
       round->NotifyReplicationFinished(Status::Aborted("Transaction aborted"));
     }
   }

http://git-wip-us.apache.org/repos/asf/incubator-kudu/blob/47d69dd6/src/kudu/gutil/charmap.h
----------------------------------------------------------------------
diff --git a/src/kudu/gutil/charmap.h b/src/kudu/gutil/charmap.h
index 1a38a96..2698bbe 100644
--- a/src/kudu/gutil/charmap.h
+++ b/src/kudu/gutil/charmap.h
@@ -64,8 +64,8 @@ class Charmap {
   }
 
   bool IsZero() const {
-    for (int i = 0; i < 8; ++i) {
-      if (m_[i] != 0)
+    for (uint32 c : m_) {
+      if (c != 0)
         return false;
     }
     return true;

http://git-wip-us.apache.org/repos/asf/incubator-kudu/blob/47d69dd6/src/kudu/gutil/map-util.h
----------------------------------------------------------------------
diff --git a/src/kudu/gutil/map-util.h b/src/kudu/gutil/map-util.h
index 565a9e2..0682c27 100644
--- a/src/kudu/gutil/map-util.h
+++ b/src/kudu/gutil/map-util.h
@@ -762,9 +762,8 @@ void AppendValuesFromMap(const MapContainer& map_container,
   if (value_container->empty()) {
     value_container->reserve(map_container.size());
   }
-  for (typename MapContainer::const_iterator it = map_container.begin();
-       it != map_container.end(); ++it) {
-    value_container->push_back(it->second);
+  for (const auto& entry : map_container) {
+    value_container->push_back(entry.second);
   }
 }
 

http://git-wip-us.apache.org/repos/asf/incubator-kudu/blob/47d69dd6/src/kudu/gutil/strings/escaping.cc
----------------------------------------------------------------------
diff --git a/src/kudu/gutil/strings/escaping.cc b/src/kudu/gutil/strings/escaping.cc
index 0a52a40..cf49359 100644
--- a/src/kudu/gutil/strings/escaping.cc
+++ b/src/kudu/gutil/strings/escaping.cc
@@ -1648,8 +1648,7 @@ void EscapeFileName(const StringPiece& src, string* dst) {
   // Reserve at least src.size() chars
   dst->reserve(dst->size() + src.size());
 
-  for (int i = 0; i < src.size(); ++i) {
-    const char c = src[i];
+  for (char c : src) {
     // We do not use "isalpha" because we want the behavior to be
     // independent of the current locale settings.
     if (escape_file_name_exceptions.contains(c)) {
@@ -1751,10 +1750,10 @@ static void b2a_hex_t(const unsigned char* b, T a, int num) {
 
 string b2a_bin(const string& b, bool byte_order_msb) {
   string result;
-  for (int byte_offset = 0; byte_offset < b.size(); ++byte_offset) {
+  for (char c : b) {
     for (int bit_offset = 0; bit_offset < 8; ++bit_offset) {
       int x = (byte_order_msb) ? 7-bit_offset : bit_offset;
-      result.append(1, (b[byte_offset] & (1 << x)) ? '1' : '0');
+      result.append(1, (c & (1 << x)) ? '1' : '0');
     }
   }
   return result;
@@ -1814,15 +1813,15 @@ string ShellEscape(StringPiece src) {
   } else {
     // needs double quote escaping
     string result = "\"";
-    for (size_t i = 0; i < src.size(); ++i) {
-      switch (src[i]) {
+    for (char c : src) {
+      switch (c) {
         case '\\':
         case '$':
         case '"':
         case '`':
           result.push_back('\\');
       };
-      result.push_back(src[i]);
+      result.push_back(c);
     }
     result.push_back('"');
     return result;

http://git-wip-us.apache.org/repos/asf/incubator-kudu/blob/47d69dd6/src/kudu/gutil/strings/join.cc
----------------------------------------------------------------------
diff --git a/src/kudu/gutil/strings/join.cc b/src/kudu/gutil/strings/join.cc
index 5454261..c0035e1 100644
--- a/src/kudu/gutil/strings/join.cc
+++ b/src/kudu/gutil/strings/join.cc
@@ -172,17 +172,17 @@ void JoinCSVLineWithDelimiter(const vector<string>& cols, char delimiter,
   // whitespace (ie ascii_isspace() returns true), escape all double-quotes and
   // bracket the string in double quotes. string.rbegin() evaluates to the last
   // character of the string.
-  for (int i = 0; i < cols.size(); ++i) {
-    if ((cols[i].find_first_of(escape_chars) != string::npos) ||
-        (!cols[i].empty() && (ascii_isspace(*cols[i].begin()) ||
-                              ascii_isspace(*cols[i].rbegin())))) {
+  for (const auto& col : cols) {
+    if ((col.find_first_of(escape_chars) != string::npos) ||
+        (!col.empty() && (ascii_isspace(*col.begin()) ||
+                              ascii_isspace(*col.rbegin())))) {
       // Double the original size, for escaping, plus two bytes for
       // the bracketing double-quotes, and one byte for the closing \0.
-      int size = 2 * cols[i].size() + 3;
+      int size = 2 * col.size() + 3;
       gscoped_array<char> buf(new char[size]);
 
       // Leave space at beginning and end for bracketing double-quotes.
-      int escaped_size = strings::EscapeStrForCSV(cols[i].c_str(),
+      int escaped_size = strings::EscapeStrForCSV(col.c_str(),
                                                   buf.get() + 1, size - 2);
       CHECK_GE(escaped_size, 0) << "Buffer somehow wasn't large enough.";
       CHECK_GE(size, escaped_size + 3)
@@ -194,7 +194,7 @@ void JoinCSVLineWithDelimiter(const vector<string>& cols, char delimiter,
       *((buf.get() + 1) + escaped_size + 1) = '\0';
       quoted_cols.push_back(string(buf.get(), buf.get() + escaped_size + 2));
     } else {
-      quoted_cols.push_back(cols[i]);
+      quoted_cols.push_back(col);
     }
   }
   JoinStrings(quoted_cols, delimiter_str, output);

http://git-wip-us.apache.org/repos/asf/incubator-kudu/blob/47d69dd6/src/kudu/gutil/strings/serialize.cc
----------------------------------------------------------------------
diff --git a/src/kudu/gutil/strings/serialize.cc b/src/kudu/gutil/strings/serialize.cc
index 56fd95b..5449ef7 100644
--- a/src/kudu/gutil/strings/serialize.cc
+++ b/src/kudu/gutil/strings/serialize.cc
@@ -223,9 +223,8 @@ int64 ReverseOrderedStringToInt64(const StringPiece& key) {
 
 string DictionaryInt32Encode(const hash_map<string, int32>* dictionary) {
   vector<string> entries;
-  for (hash_map<string, int32>::const_iterator iter = dictionary->begin();
-       iter != dictionary->end(); ++iter) {
-    entries.push_back(StringPrintf("%s:%d", iter->first.c_str(), iter->second));
+  for (const auto& entry : *dictionary) {
+    entries.push_back(StringPrintf("%s:%d", entry.first.c_str(), entry.second));
   }
 
   string result;
@@ -235,10 +234,9 @@ string DictionaryInt32Encode(const hash_map<string, int32>* dictionary) {
 
 string DictionaryInt64Encode(const hash_map<string, int64>* dictionary) {
   vector<string> entries;
-  for (hash_map<string, int64>::const_iterator iter = dictionary->begin();
-       iter != dictionary->end(); ++iter) {
+  for (const auto& entry : *dictionary) {
     entries.push_back(StringPrintf("%s:%" PRId64,
-                                   iter->first.c_str(), iter->second));
+                                   entry.first.c_str(), entry.second));
   }
 
   string result;
@@ -248,9 +246,8 @@ string DictionaryInt64Encode(const hash_map<string, int64>* dictionary) {
 
 string DictionaryDoubleEncode(const hash_map<string, double>* dictionary) {
   vector<string> entries;
-  for (hash_map<string, double>::const_iterator iter = dictionary->begin();
-       iter != dictionary->end(); ++iter) {
-    entries.push_back(StringPrintf("%s:%g", iter->first.c_str(), iter->second));
+  for (const auto& entry : *dictionary) {
+    entries.push_back(StringPrintf("%s:%g", entry.first.c_str(), entry.second));
   }
 
   string result;
@@ -259,12 +256,12 @@ string DictionaryDoubleEncode(const hash_map<string, double>* dictionary) {
 }
 
 bool DictionaryParse(const string& encoded_str,
-                      vector<pair<string, string> >* items) {
+                     vector<pair<string, string> >* items) {
   vector<string> entries;
   SplitStringUsing(encoded_str, ",", &entries);
-  for (int i = 0; i < entries.size(); ++i) {
+  for (const auto& entry : entries) {
     vector<string> fields;
-    SplitStringAllowEmpty(entries[i], ":", &fields);
+    SplitStringAllowEmpty(entry, ":", &fields);
     if (fields.size() != 2)  // parsing error
       return false;
     items->push_back(make_pair(fields[0], fields[1]));
@@ -279,14 +276,14 @@ bool DictionaryInt32Decode(hash_map<string, int32>* dictionary,
     return false;
 
   dictionary->clear();
-  for (int i = 0; i < items.size(); ++i) {
+  for (const auto& item : items) {
     char *error = nullptr;
-    const int32 value = strto32(items[i].second.c_str(), &error, 0);
-    if (error == items[i].second.c_str() || *error != '\0') {
+    const int32 value = strto32(item.second.c_str(), &error, 0);
+    if (error == item.second.c_str() || *error != '\0') {
       // parsing error
       return false;
     }
-    (*dictionary)[items[i].first] = value;
+    (*dictionary)[item.first] = value;
   }
   return true;
 }
@@ -298,14 +295,14 @@ bool DictionaryInt64Decode(hash_map<string, int64>* dictionary,
     return false;
 
   dictionary->clear();
-  for (int i = 0; i < items.size(); ++i) {
+  for (const auto& item : items) {
     char *error = nullptr;
-    const int64 value = strto64(items[i].second.c_str(), &error, 0);
-    if (error == items[i].second.c_str() || *error != '\0')  {
+    const int64 value = strto64(item.second.c_str(), &error, 0);
+    if (error == item.second.c_str() || *error != '\0')  {
       // parsing error
       return false;
     }
-    (*dictionary)[items[i].first] = value;
+    (*dictionary)[item.first] = value;
   }
   return true;
 }
@@ -318,14 +315,14 @@ bool DictionaryDoubleDecode(hash_map<string, double>* dictionary,
     return false;
 
   dictionary->clear();
-  for (int i = 0; i < items.size(); ++i) {
+  for (const auto& item : items) {
     char *error = nullptr;
-    const double value = strtod(items[i].second.c_str(), &error);
-    if (error == items[i].second.c_str() || *error != '\0') {
+    const double value = strtod(item.second.c_str(), &error);
+    if (error == item.second.c_str() || *error != '\0') {
       // parsing error
       return false;
     }
-    (*dictionary)[items[i].first] = value;
+    (*dictionary)[item.first] = value;
   }
   return true;
 }

http://git-wip-us.apache.org/repos/asf/incubator-kudu/blob/47d69dd6/src/kudu/gutil/strings/split.cc
----------------------------------------------------------------------
diff --git a/src/kudu/gutil/strings/split.cc b/src/kudu/gutil/strings/split.cc
index 2e39a52..a42faa7 100644
--- a/src/kudu/gutil/strings/split.cc
+++ b/src/kudu/gutil/strings/split.cc
@@ -133,8 +133,8 @@ void AppendToImpl(vector<string>* container, Splitter splitter) {
   vector<StringPiece> vsp = splitter;  // Calls implicit conversion operator.
   size_t container_size = container->size();
   container->resize(container_size + vsp.size());
-  for (size_t i = 0; i < vsp.size(); ++i) {
-    vsp[i].CopyToString(&(*container)[container_size++]);
+  for (const auto& sp : vsp) {
+    sp.CopyToString(&(*container)[container_size++]);
   }
 }
 
@@ -1004,10 +1004,10 @@ bool SplitStringIntoKeyValuePairs(const string& line,
   SplitStringUsing(line, key_value_pair_delimiters.c_str(), &pairs);
 
   bool success = true;
-  for (size_t i = 0; i < pairs.size(); ++i) {
+  for (const auto& pair : pairs) {
     string key;
     vector<string> value;
-    if (!SplitStringIntoKeyValues(pairs[i],
+    if (!SplitStringIntoKeyValues(pair,
                                   key_value_delimiters,
                                   "", &key, &value)) {
       // Don't return here, to allow for keys without associated

http://git-wip-us.apache.org/repos/asf/incubator-kudu/blob/47d69dd6/src/kudu/gutil/strings/split.h
----------------------------------------------------------------------
diff --git a/src/kudu/gutil/strings/split.h b/src/kudu/gutil/strings/split.h
index d90b96b..c487689 100644
--- a/src/kudu/gutil/strings/split.h
+++ b/src/kudu/gutil/strings/split.h
@@ -1156,9 +1156,9 @@ bool SplitStringAndParseToInserter(
   vector<StringPiece> pieces = strings::Split(source,
                                               strings::delimiter::AnyOf(delim),
                                               strings::SkipEmpty());
-  for (size_t i = 0; i < pieces.size(); ++i) {
+  for (const auto& piece : pieces) {
     typename Container::value_type t;
-    if (parse(pieces[i].as_string(), &t)) {
+    if (parse(piece.as_string(), &t)) {
       insert_policy(result, t);
     } else {
       retval = false;

http://git-wip-us.apache.org/repos/asf/incubator-kudu/blob/47d69dd6/src/kudu/gutil/strings/split_internal.h
----------------------------------------------------------------------
diff --git a/src/kudu/gutil/strings/split_internal.h b/src/kudu/gutil/strings/split_internal.h
index 1b68554..01b3fac 100644
--- a/src/kudu/gutil/strings/split_internal.h
+++ b/src/kudu/gutil/strings/split_internal.h
@@ -329,8 +329,8 @@ class Splitter {
     Container c;
     ReserveCapacity(&c, v.size());
     std::insert_iterator<Container> inserter(c, c.begin());
-    for (size_t i = 0; i < v.size(); ++i) {
-      *inserter++ = converter(v[i]);
+    for (const auto& sp : v) {
+      *inserter++ = converter(sp);
     }
     return c;
   }

http://git-wip-us.apache.org/repos/asf/incubator-kudu/blob/47d69dd6/src/kudu/gutil/strings/strip.cc
----------------------------------------------------------------------
diff --git a/src/kudu/gutil/strings/strip.cc b/src/kudu/gutil/strings/strip.cc
index 112ac31..1a6a547 100644
--- a/src/kudu/gutil/strings/strip.cc
+++ b/src/kudu/gutil/strings/strip.cc
@@ -74,9 +74,9 @@ void StripString(char* str, int len, StringPiece remove, char replacewith) {
 }
 
 void StripString(string* s, StringPiece remove, char replacewith) {
-  for (string::iterator it = s->begin(), end = s->end(); it != end; ++it) {
-    if (remove.find(*it) != StringPiece::npos) {
-      *it = replacewith;
+  for (char& c : *s) {
+    if (remove.find(c) != StringPiece::npos) {
+      c = replacewith;
     }
   }
 }

http://git-wip-us.apache.org/repos/asf/incubator-kudu/blob/47d69dd6/src/kudu/gutil/strings/util.cc
----------------------------------------------------------------------
diff --git a/src/kudu/gutil/strings/util.cc b/src/kudu/gutil/strings/util.cc
index 715112b..c16d9b2 100644
--- a/src/kudu/gutil/strings/util.cc
+++ b/src/kudu/gutil/strings/util.cc
@@ -1092,8 +1092,8 @@ StringPiece FindEol(StringPiece s) {
 //  return true if string s contains only whitespace characters
 //------------------------------------------------------------------------
 bool OnlyWhitespace(const StringPiece& s) {
-  for ( int i = 0; i < s.size(); ++i ) {
-    if ( !ascii_isspace(s[i]) ) return false;
+  for (const auto& c : s) {
+    if ( !ascii_isspace(c) ) return false;
   }
   return true;
 }

http://git-wip-us.apache.org/repos/asf/incubator-kudu/blob/47d69dd6/src/kudu/integration-tests/alter_table-randomized-test.cc
----------------------------------------------------------------------
diff --git a/src/kudu/integration-tests/alter_table-randomized-test.cc b/src/kudu/integration-tests/alter_table-randomized-test.cc
index 99b1b0a..cbf1bfd 100644
--- a/src/kudu/integration-tests/alter_table-randomized-test.cc
+++ b/src/kudu/integration-tests/alter_table-randomized-test.cc
@@ -366,11 +366,11 @@ struct MirrorTable {
       case UPDATE: op.reset(table->NewUpdate()); break;
       case DELETE: op.reset(table->NewDelete()); break;
     }
-    for (int i = 0; i < data.size(); i++) {
-      if (data[i].second == RowState::kNullValue) {
-        CHECK_OK(op->mutable_row()->SetNull(data[i].first));
+    for (const auto& d : data) {
+      if (d.second == RowState::kNullValue) {
+        CHECK_OK(op->mutable_row()->SetNull(d.first));
       } else {
-        CHECK_OK(op->mutable_row()->SetInt32(data[i].first, data[i].second));
+        CHECK_OK(op->mutable_row()->SetInt32(d.first, d.second));
       }
     }
     RETURN_NOT_OK(session->Apply(op.release()));

http://git-wip-us.apache.org/repos/asf/incubator-kudu/blob/47d69dd6/src/kudu/integration-tests/mini_cluster.cc
----------------------------------------------------------------------
diff --git a/src/kudu/integration-tests/mini_cluster.cc b/src/kudu/integration-tests/mini_cluster.cc
index ab45391..584822f 100644
--- a/src/kudu/integration-tests/mini_cluster.cc
+++ b/src/kudu/integration-tests/mini_cluster.cc
@@ -280,8 +280,8 @@ Status MiniCluster::WaitForTabletServerCount(int count,
       // are aligned (same uuid/seqno) with the TSs that we have in the cluster.
       int match_count = 0;
       for (const shared_ptr<TSDescriptor>& desc : *descs) {
-        for (int i = 0; i < mini_tablet_servers_.size(); ++i) {
-          TabletServer *ts = mini_tablet_servers_[i]->server();
+        for (auto mini_tablet_server : mini_tablet_servers_) {
+          auto ts = mini_tablet_server->server();
           if (ts->instance_pb().permanent_uuid() == desc->permanent_uuid() &&
               ts->instance_pb().instance_seqno() == desc->latest_seqno()) {
             match_count++;

http://git-wip-us.apache.org/repos/asf/incubator-kudu/blob/47d69dd6/src/kudu/rpc/mt-rpc-test.cc
----------------------------------------------------------------------
diff --git a/src/kudu/rpc/mt-rpc-test.cc b/src/kudu/rpc/mt-rpc-test.cc
index c9ed7c8..6b05784 100644
--- a/src/kudu/rpc/mt-rpc-test.cc
+++ b/src/kudu/rpc/mt-rpc-test.cc
@@ -215,16 +215,16 @@ TEST_F(MultiThreadedRpcTest, TestBlowOutServiceQueue) {
   service_pool_->Shutdown();
   server_messenger_->Shutdown();
 
-  for (int i = 0; i < 3; i++) {
-    ASSERT_OK(ThreadJoiner(threads[i].get()).warn_every_ms(500).Join());
+  for (const auto& thread : threads) {
+    ASSERT_OK(ThreadJoiner(thread.get()).warn_every_ms(500).Join());
   }
 
   // Verify that one error was due to backpressure.
   int errors_backpressure = 0;
   int errors_shutdown = 0;
 
-  for (int i = 0; i < 3; i++) {
-    IncrementBackpressureOrShutdown(&status[i], &errors_backpressure, &errors_shutdown);
+  for (const auto& s : status) {
+    IncrementBackpressureOrShutdown(&s, &errors_backpressure, &errors_shutdown);
   }
 
   ASSERT_EQ(1, errors_backpressure);

http://git-wip-us.apache.org/repos/asf/incubator-kudu/blob/47d69dd6/src/kudu/tablet/mt-rowset_delta_compaction-test.cc
----------------------------------------------------------------------
diff --git a/src/kudu/tablet/mt-rowset_delta_compaction-test.cc b/src/kudu/tablet/mt-rowset_delta_compaction-test.cc
index 0191ee6..c9e8004 100644
--- a/src/kudu/tablet/mt-rowset_delta_compaction-test.cc
+++ b/src/kudu/tablet/mt-rowset_delta_compaction-test.cc
@@ -129,17 +129,17 @@ class TestMultiThreadedRowSetDeltaCompaction : public TestRowSet {
   }
 
   void JoinThreads() {
-    for (int i = 0; i < update_threads_.size(); i++) {
-      ASSERT_OK(ThreadJoiner(update_threads_[i].get()).Join());
+    for (const auto& thread : update_threads_) {
+      ASSERT_OK(ThreadJoiner(thread.get()).Join());
     }
-    for (int i = 0; i < flush_threads_.size(); i++) {
-      ASSERT_OK(ThreadJoiner(flush_threads_[i].get()).Join());
+    for (const auto& thread : flush_threads_) {
+      ASSERT_OK(ThreadJoiner(thread.get()).Join());
     }
-    for (int i = 0; i < compaction_threads_.size(); i++) {
-      ASSERT_OK(ThreadJoiner(compaction_threads_[i].get()).Join());
+    for (const auto& thread : compaction_threads_) {
+      ASSERT_OK(ThreadJoiner(thread.get()).Join());
     }
-    for (int i = 0; i < alter_schema_threads_.size(); i++) {
-      ASSERT_OK(ThreadJoiner(alter_schema_threads_[i].get()).Join());
+    for (const auto& thread : alter_schema_threads_) {
+      ASSERT_OK(ThreadJoiner(thread.get()).Join());
     }
   }
 

http://git-wip-us.apache.org/repos/asf/incubator-kudu/blob/47d69dd6/src/kudu/tablet/mvcc.cc
----------------------------------------------------------------------
diff --git a/src/kudu/tablet/mvcc.cc b/src/kudu/tablet/mvcc.cc
index 313a858..f972379 100644
--- a/src/kudu/tablet/mvcc.cc
+++ b/src/kudu/tablet/mvcc.cc
@@ -241,9 +241,9 @@ void MvccManager::OfflineAdjustSafeTime(Timestamp safe_time) {
 static void FilterTimestamps(std::vector<Timestamp::val_type>* v,
                              Timestamp::val_type watermark) {
   int j = 0;
-  for (int i = 0; i < v->size(); i++) {
-    if ((*v)[i] >= watermark) {
-      (*v)[j++] = (*v)[i];
+  for (const auto& ts : *v) {
+    if (ts >= watermark) {
+      (*v)[j++] = ts;
     }
   }
   v->resize(j);

http://git-wip-us.apache.org/repos/asf/incubator-kudu/blob/47d69dd6/src/kudu/tablet/tablet-test-util.h
----------------------------------------------------------------------
diff --git a/src/kudu/tablet/tablet-test-util.h b/src/kudu/tablet/tablet-test-util.h
index 89c7591..1b25538 100644
--- a/src/kudu/tablet/tablet-test-util.h
+++ b/src/kudu/tablet/tablet-test-util.h
@@ -175,8 +175,8 @@ static inline void CollectRowsForSnapshots(Tablet* tablet,
     ASSERT_OK(iter->Init(NULL));
     auto collector = new vector<string>();
     ASSERT_OK(IterateToStringList(iter.get(), collector));
-    for (int i = 0; i < collector->size(); i++) {
-      DVLOG(1) << "Got from MRS: " << (*collector)[i];
+    for (const auto& mrs : *collector) {
+      DVLOG(1) << "Got from MRS: " << mrs;
     }
     collected_rows->push_back(collector);
   }

http://git-wip-us.apache.org/repos/asf/incubator-kudu/blob/47d69dd6/src/kudu/util/auto_release_pool.h
----------------------------------------------------------------------
diff --git a/src/kudu/util/auto_release_pool.h b/src/kudu/util/auto_release_pool.h
index cb1d811..eaed9c2 100644
--- a/src/kudu/util/auto_release_pool.h
+++ b/src/kudu/util/auto_release_pool.h
@@ -33,9 +33,8 @@ class AutoReleasePool {
   AutoReleasePool(): objects_() { }
 
   ~AutoReleasePool() {
-    for (ElementVector::iterator i = objects_.begin();
-         i != objects_.end(); ++i) {
-      delete *i;
+    for (auto& object : objects_) {
+      delete object;
     }
   }
 

http://git-wip-us.apache.org/repos/asf/incubator-kudu/blob/47d69dd6/src/kudu/util/blocking_queue-test.cc
----------------------------------------------------------------------
diff --git a/src/kudu/util/blocking_queue-test.cc b/src/kudu/util/blocking_queue-test.cc
index 7aa3c96..876b451 100644
--- a/src/kudu/util/blocking_queue-test.cc
+++ b/src/kudu/util/blocking_queue-test.cc
@@ -180,9 +180,8 @@ class MultiThreadTest {
     threads_.push_back(shared_ptr<boost::thread>(
             new boost::thread(boost::bind(
               &MultiThreadTest::RemoverThread, this))));
-    for (thread_vec_t::iterator t = threads_.begin();
-         t != threads_.end(); ++t) {
-      (*t)->join();
+    for (const auto& thread : threads_) {
+      thread->join();
     }
     // Let's check to make sure we got what we should have.
     MutexLock guard(lock_);

http://git-wip-us.apache.org/repos/asf/incubator-kudu/blob/47d69dd6/src/kudu/util/debug/trace_event_impl.cc
----------------------------------------------------------------------
diff --git a/src/kudu/util/debug/trace_event_impl.cc b/src/kudu/util/debug/trace_event_impl.cc
index 6f3e5e9..b3e2e5f 100644
--- a/src/kudu/util/debug/trace_event_impl.cc
+++ b/src/kudu/util/debug/trace_event_impl.cc
@@ -503,8 +503,9 @@ TraceEvent::TraceEvent()
       thread_id_(0),
       phase_(TRACE_EVENT_PHASE_BEGIN),
       flags_(0) {
-  for (int i = 0; i < kTraceMaxNumArgs; ++i)
-    arg_names_[i] = nullptr;
+  for (auto& arg_name : arg_names_) {
+    arg_name = nullptr;
+  }
   memset(arg_values_, 0, sizeof(arg_values_));
 }
 
@@ -967,8 +968,8 @@ void TraceSamplingThread::DefaultSamplingCallback(
 }
 
 void TraceSamplingThread::GetSamples() {
-  for (size_t i = 0; i < sample_buckets_.size(); ++i) {
-    TraceBucketData* bucket_data = &sample_buckets_[i];
+  for (auto& sample_bucket : sample_buckets_) {
+    TraceBucketData* bucket_data = &sample_bucket;
     bucket_data->callback.Run(bucket_data);
   }
 }
@@ -1351,8 +1352,8 @@ void TraceLog::SetEnabled(const CategoryFilter& category_filter,
     observer_list = enabled_state_observer_list_;
   }
   // Notify observers outside the lock in case they trigger trace events.
-  for (size_t i = 0; i < observer_list.size(); ++i)
-    observer_list[i]->OnTraceLogEnabled();
+  for (const auto& observer : observer_list)
+    observer->OnTraceLogEnabled();
 
   {
     SpinLockHolder lock(&lock_);
@@ -1408,8 +1409,8 @@ void TraceLog::SetDisabledWhileLocked() {
     // Dispatch to observers outside the lock in case the observer triggers a
     // trace event.
     lock_.Unlock();
-    for (size_t i = 0; i < observer_list.size(); ++i)
-      observer_list[i]->OnTraceLogDisabled();
+    for (const auto& observer : observer_list)
+      observer->OnTraceLogDisabled();
     lock_.Lock();
   }
   dispatching_to_observer_list_ = false;
@@ -2070,10 +2071,8 @@ void TraceLog::AddMetadataEventsWhileLocked() {
 
   if (process_labels_.size() > 0) {
     std::vector<std::string> labels;
-    for(std::unordered_map<int, std::string>::iterator it = process_labels_.begin();
-        it != process_labels_.end();
-        it++) {
-      labels.push_back(it->second);
+    for(auto& label : process_labels_) {
+      labels.push_back(label.second);
     }
     InitializeMetadataEvent(AddEventToThreadSharedChunkWhileLocked(nullptr, false),
                             current_thread_id,
@@ -2082,28 +2081,24 @@ void TraceLog::AddMetadataEventsWhileLocked() {
   }
 
   // Thread sort indices.
-  for(std::unordered_map<int, int>::iterator it = thread_sort_indices_.begin();
-      it != thread_sort_indices_.end();
-      it++) {
-    if (it->second == 0)
+  for(auto& sort_index : thread_sort_indices_) {
+    if (sort_index.second == 0)
       continue;
     InitializeMetadataEvent(AddEventToThreadSharedChunkWhileLocked(nullptr, false),
-                            it->first,
+                            sort_index.first,
                             "thread_sort_index", "sort_index",
-                            it->second);
+                            sort_index.second);
   }
 
   // Thread names.
   SpinLockHolder thread_info_lock(&thread_info_lock_);
-  for(std::unordered_map<int, std::string>::iterator it = thread_names_.begin();
-      it != thread_names_.end();
-      it++) {
-    if (it->second.empty())
+  for(auto& name : thread_names_) {
+    if (name.second.empty())
       continue;
     InitializeMetadataEvent(AddEventToThreadSharedChunkWhileLocked(nullptr, false),
-                            it->first,
+                            name.first,
                             "thread_name", "name",
-                            it->second);
+                            name.second);
   }
 }
 
@@ -2289,11 +2284,10 @@ void CategoryFilter::WriteString(const StringList& values,
                                  bool included) const {
   bool prepend_comma = !out->empty();
   int token_cnt = 0;
-  for (StringList::const_iterator ci = values.begin();
-       ci != values.end(); ++ci) {
+  for (const auto& value : values) {
     if (token_cnt > 0 || prepend_comma)
       StringAppendF(out, ",");
-    StringAppendF(out, "%s%s", (included ? "" : "-"), ci->c_str());
+    StringAppendF(out, "%s%s", (included ? "" : "-"), value.c_str());
     ++token_cnt;
   }
 }
@@ -2302,12 +2296,11 @@ void CategoryFilter::WriteString(const StringList& delays,
                                  std::string* out) const {
   bool prepend_comma = !out->empty();
   int token_cnt = 0;
-  for (StringList::const_iterator ci = delays.begin();
-       ci != delays.end(); ++ci) {
+  for (const auto& delay : delays) {
     if (token_cnt > 0 || prepend_comma)
       StringAppendF(out, ",");
     StringAppendF(out, "%s%s)", kSyntheticDelayCategoryFilterPrefix,
-                  ci->c_str());
+                  delay.c_str());
     ++token_cnt;
   }
 }

http://git-wip-us.apache.org/repos/asf/incubator-kudu/blob/47d69dd6/src/kudu/util/mem_tracker.cc
----------------------------------------------------------------------
diff --git a/src/kudu/util/mem_tracker.cc b/src/kudu/util/mem_tracker.cc
index 3bee9cf..1f13347 100644
--- a/src/kudu/util/mem_tracker.cc
+++ b/src/kudu/util/mem_tracker.cc
@@ -284,11 +284,10 @@ void MemTracker::Consume(int64_t bytes) {
   if (PREDICT_FALSE(enable_logging_)) {
     LogUpdate(true, bytes);
   }
-  for (vector<MemTracker*>::iterator tracker = all_trackers_.begin();
-       tracker != all_trackers_.end(); ++tracker) {
-    (*tracker)->consumption_.IncrementBy(bytes);
-    if (!(*tracker)->consumption_func_.empty()) {
-      DCHECK_GE((*tracker)->consumption_.current_value(), 0);
+  for (auto& tracker : all_trackers_) {
+    tracker->consumption_.IncrementBy(bytes);
+    if (!tracker->consumption_func_.empty()) {
+      DCHECK_GE(tracker->consumption_.current_value(), 0);
     }
   }
 }
@@ -370,25 +369,23 @@ void MemTracker::Release(int64_t bytes) {
     LogUpdate(false, bytes);
   }
 
-  for (vector<MemTracker*>::iterator tracker = all_trackers_.begin();
-       tracker != all_trackers_.end(); ++tracker) {
-    (*tracker)->consumption_.IncrementBy(-bytes);
+  for (auto& tracker : all_trackers_) {
+    tracker->consumption_.IncrementBy(-bytes);
     // If a UDF calls FunctionContext::TrackAllocation() but allocates less than the
     // reported amount, the subsequent call to FunctionContext::Free() may cause the
     // process mem tracker to go negative until it is synced back to the tcmalloc
     // metric. Don't blow up in this case. (Note that this doesn't affect non-process
     // trackers since we can enforce that the reported memory usage is internally
     // consistent.)
-    if (!(*tracker)->consumption_func_.empty()) {
-      DCHECK_GE((*tracker)->consumption_.current_value(), 0);
+    if (!tracker->consumption_func_.empty()) {
+      DCHECK_GE(tracker->consumption_.current_value(), 0);
     }
   }
 }
 
 bool MemTracker::AnyLimitExceeded() {
-  for (vector<MemTracker*>::iterator tracker = limit_trackers_.begin();
-       tracker != limit_trackers_.end(); ++tracker) {
-    if ((*tracker)->LimitExceeded()) {
+  for (const auto& tracker : limit_trackers_) {
+    if (tracker->LimitExceeded()) {
       return true;
     }
   }
@@ -446,9 +443,8 @@ bool MemTracker::AnySoftLimitExceeded(double* current_capacity_pct) {
 
 int64_t MemTracker::SpareCapacity() const {
   int64_t result = std::numeric_limits<int64_t>::max();
-  for (vector<MemTracker*>::const_iterator tracker = limit_trackers_.begin();
-       tracker != limit_trackers_.end(); ++tracker) {
-    int64_t mem_left = (*tracker)->limit() - (*tracker)->consumption();
+  for (const auto& tracker : limit_trackers_) {
+    int64_t mem_left = tracker->limit() - tracker->consumption();
     result = std::min(result, mem_left);
   }
   return result;
@@ -471,8 +467,8 @@ bool MemTracker::GcMemory(int64_t max_consumption) {
   }
 
   // Try to free up some memory
-  for (int i = 0; i < gc_functions_.size(); ++i) {
-    gc_functions_[i]();
+  for (const auto& gc_function : gc_functions_) {
+    gc_function();
     if (!consumption_func_.empty()) {
       UpdateConsumption();
     }

http://git-wip-us.apache.org/repos/asf/incubator-kudu/blob/47d69dd6/src/kudu/util/memenv/memenv.cc
----------------------------------------------------------------------
diff --git a/src/kudu/util/memenv/memenv.cc b/src/kudu/util/memenv/memenv.cc
index 9bf5a28..92b2007 100644
--- a/src/kudu/util/memenv/memenv.cc
+++ b/src/kudu/util/memenv/memenv.cc
@@ -437,8 +437,8 @@ class InMemoryEnv : public EnvWrapper {
     MutexLock lock(mutex_);
     result->clear();
 
-    for (FileSystem::iterator i = file_map_.begin(); i != file_map_.end(); ++i) {
-      const std::string& filename = i->first;
+    for (const auto& file : file_map_) {
+      const std::string& filename = file.first;
 
       if (filename.size() >= dir.size() + 1 && filename[dir.size()] == '/' &&
           Slice(filename).starts_with(Slice(dir))) {

http://git-wip-us.apache.org/repos/asf/incubator-kudu/blob/47d69dd6/src/kudu/util/rle-test.cc
----------------------------------------------------------------------
diff --git a/src/kudu/util/rle-test.cc b/src/kudu/util/rle-test.cc
index 5d0266f..b220b30 100644
--- a/src/kudu/util/rle-test.cc
+++ b/src/kudu/util/rle-test.cc
@@ -190,8 +190,8 @@ void ValidateRle(const vector<T>& values, int bit_width,
   faststring buffer;
   RleEncoder<T> encoder(&buffer, bit_width);
 
-  for (int i = 0; i < values.size(); ++i) {
-    encoder.Put(values[i]);
+  for (const auto& value : values) {
+    encoder.Put(value);
   }
   int encoded_len = encoder.Flush();
 
@@ -207,11 +207,11 @@ void ValidateRle(const vector<T>& values, int bit_width,
 
   // Verify read
   RleDecoder<T> decoder(buffer.data(), encoded_len, bit_width);
-  for (int i = 0; i < values.size(); ++i) {
+  for (const auto& value : values) {
     T val = 0;
     bool result = decoder.Get(&val);
     EXPECT_TRUE(result);
-    EXPECT_EQ(values[i], val);
+    EXPECT_EQ(value, val);
   }
 }
 

http://git-wip-us.apache.org/repos/asf/incubator-kudu/blob/47d69dd6/src/kudu/util/string_case.cc
----------------------------------------------------------------------
diff --git a/src/kudu/util/string_case.cc b/src/kudu/util/string_case.cc
index b85879a..141cdc5 100644
--- a/src/kudu/util/string_case.cc
+++ b/src/kudu/util/string_case.cc
@@ -31,8 +31,7 @@ void SnakeToCamelCase(const std::string &snake_case,
   camel_case->reserve(snake_case.size());
 
   bool uppercase_next = true;
-  for (int i = 0; i < snake_case.size(); i++) {
-    char c = snake_case[i];
+  for (char c : snake_case) {
     if ((c == '_') ||
         (c == '-')) {
       uppercase_next = true;
@@ -53,8 +52,8 @@ void ToUpperCase(const std::string &string,
     *out = string;
   }
 
-  for (int i = 0; i < out->size(); i++) {
-    (*out)[i] = toupper((*out)[i]);
+  for (char& c : *out) {
+    c = toupper(c);
   }
 }
 



Mime
View raw message