Fix up TODO: c++0x, update cpplint.

Needed to update cpplint to handle const auto.

Fixed a few cpplint errors that were being missed before.

Replaced most of the TODO c++0x with ranged based loops. Loops which
do not have a descriptive container name have a concrete type instead
of auto.

Change-Id: Id7cc0f27030f56057c544e94277300b3f298c9c5
diff --git a/runtime/gc/accounting/gc_allocator.cc b/runtime/gc/accounting/gc_allocator.cc
index 0b0d3ed..11d0e67 100644
--- a/runtime/gc/accounting/gc_allocator.cc
+++ b/runtime/gc/accounting/gc_allocator.cc
@@ -31,6 +31,6 @@
     Runtime::Current()->GetHeap()->RegisterGCDeAllocation(bytes);
     free(p);
   }
-}
-}
-}
+}  // namespace accounting
+}  // namespace gc
+}  // namespace art
diff --git a/runtime/gc/accounting/gc_allocator.h b/runtime/gc/accounting/gc_allocator.h
index d1356a7..1fba858 100644
--- a/runtime/gc/accounting/gc_allocator.h
+++ b/runtime/gc/accounting/gc_allocator.h
@@ -75,8 +75,8 @@
                                           GCAllocatorImpl<T>,
                                           std::allocator<T> >::value {
   };
-}
-}
-}
+}  // namespace accounting
+}  // namespace gc
+}  // namespace art
 
 #endif  // ART_RUNTIME_GC_ACCOUNTING_GC_ALLOCATOR_H_
diff --git a/runtime/gc/accounting/heap_bitmap-inl.h b/runtime/gc/accounting/heap_bitmap-inl.h
index 0524ccb..18b93d4 100644
--- a/runtime/gc/accounting/heap_bitmap-inl.h
+++ b/runtime/gc/accounting/heap_bitmap-inl.h
@@ -25,20 +25,12 @@
 
 template <typename Visitor>
 inline void HeapBitmap::Visit(const Visitor& visitor) {
-  // TODO: C++0x auto
-  typedef SpaceBitmapVector::iterator It;
-  for (It it = continuous_space_bitmaps_.begin(), end = continuous_space_bitmaps_.end();
-      it != end; ++it) {
-    SpaceBitmap* bitmap = *it;
+  for (const auto& bitmap : continuous_space_bitmaps_) {
     bitmap->VisitMarkedRange(bitmap->HeapBegin(), bitmap->HeapLimit(), visitor);
   }
-  // TODO: C++0x auto
-  typedef SpaceSetMapVector::iterator It2;
-  DCHECK(discontinuous_space_sets_.begin() !=  discontinuous_space_sets_.end());
-  for (It2 it = discontinuous_space_sets_.begin(), end = discontinuous_space_sets_.end();
-      it != end; ++it) {
-    SpaceSetMap* set = *it;
-    set->Visit(visitor);
+  DCHECK(!discontinuous_space_sets_.empty());
+  for (const auto& space_set : discontinuous_space_sets_) {
+    space_set->Visit(visitor);
   }
 }
 
diff --git a/runtime/gc/accounting/heap_bitmap.cc b/runtime/gc/accounting/heap_bitmap.cc
index 0462905..5589461 100644
--- a/runtime/gc/accounting/heap_bitmap.cc
+++ b/runtime/gc/accounting/heap_bitmap.cc
@@ -23,12 +23,9 @@
 namespace accounting {
 
 void HeapBitmap::ReplaceBitmap(SpaceBitmap* old_bitmap, SpaceBitmap* new_bitmap) {
-  // TODO: C++0x auto
-  typedef SpaceBitmapVector::iterator It;
-  for (It it = continuous_space_bitmaps_.begin(), end = continuous_space_bitmaps_.end();
-      it != end; ++it) {
-    if (*it == old_bitmap) {
-      *it = new_bitmap;
+  for (auto& bitmap : continuous_space_bitmaps_) {
+    if (bitmap == old_bitmap) {
+      bitmap = new_bitmap;
       return;
     }
   }
@@ -36,12 +33,9 @@
 }
 
 void HeapBitmap::ReplaceObjectSet(SpaceSetMap* old_set, SpaceSetMap* new_set) {
-  // TODO: C++0x auto
-  typedef SpaceSetMapVector::iterator It;
-  for (It it = discontinuous_space_sets_.begin(), end = discontinuous_space_sets_.end();
-      it != end; ++it) {
-    if (*it == old_set) {
-      *it = new_set;
+  for (auto& space_set : discontinuous_space_sets_) {
+    if (space_set == old_set) {
+      space_set = new_set;
       return;
     }
   }
@@ -52,13 +46,10 @@
   DCHECK(bitmap != NULL);
 
   // Check for interval overlap.
-  typedef SpaceBitmapVector::iterator It;
-  for (It it = continuous_space_bitmaps_.begin(), end = continuous_space_bitmaps_.end();
-      it != end; ++it) {
-    SpaceBitmap* bitmap = *it;
-    SpaceBitmap* cur_bitmap = *it;
-    CHECK(bitmap->HeapBegin() < cur_bitmap->HeapLimit() &&
-          bitmap->HeapLimit() > cur_bitmap->HeapBegin())
+  for (const auto& cur_bitmap : continuous_space_bitmaps_) {
+    CHECK(!(
+        bitmap->HeapBegin() < cur_bitmap->HeapLimit() &&
+        bitmap->HeapLimit() > cur_bitmap->HeapBegin()))
         << "Bitmap " << bitmap->Dump() << " overlaps with existing bitmap " << cur_bitmap->Dump();
   }
   continuous_space_bitmaps_.push_back(bitmap);
@@ -70,20 +61,13 @@
 }
 
 void HeapBitmap::Walk(SpaceBitmap::Callback* callback, void* arg) {
-  // TODO: C++0x auto
-  typedef SpaceBitmapVector::iterator It;
-  for (It it = continuous_space_bitmaps_.begin(), end = continuous_space_bitmaps_.end();
-      it != end; ++it) {
-    SpaceBitmap* bitmap = *it;
+  for (const auto& bitmap : continuous_space_bitmaps_) {
     bitmap->Walk(callback, arg);
   }
-  // TODO: C++0x auto
-  typedef SpaceSetMapVector::iterator It2;
-  DCHECK(discontinuous_space_sets_.begin() !=  discontinuous_space_sets_.end());
-  for (It2 it = discontinuous_space_sets_.begin(), end = discontinuous_space_sets_.end();
-      it != end; ++it) {
-    SpaceSetMap* set = *it;
-    set->Walk(callback, arg);
+
+  DCHECK(!discontinuous_space_sets_.empty());
+  for (const auto& space_set : discontinuous_space_sets_) {
+    space_set->Walk(callback, arg);
   }
 }
 
diff --git a/runtime/gc/accounting/heap_bitmap.h b/runtime/gc/accounting/heap_bitmap.h
index ada976f..2ca8c4a 100644
--- a/runtime/gc/accounting/heap_bitmap.h
+++ b/runtime/gc/accounting/heap_bitmap.h
@@ -66,11 +66,7 @@
   }
 
   SpaceBitmap* GetContinuousSpaceBitmap(const mirror::Object* obj) {
-    // TODO: C++0x auto
-    typedef SpaceBitmapVector::iterator It;
-    for (It it = continuous_space_bitmaps_.begin(), end = continuous_space_bitmaps_.end();
-        it != end; ++it) {
-      SpaceBitmap* bitmap = *it;
+    for (const auto& bitmap : continuous_space_bitmaps_) {
       if (bitmap->HasAddress(obj)) {
         return bitmap;
       }
@@ -79,13 +75,9 @@
   }
 
   SpaceSetMap* GetDiscontinuousSpaceObjectSet(const mirror::Object* obj) {
-    // TODO: C++0x auto
-    typedef SpaceSetMapVector::iterator It;
-    for (It it = discontinuous_space_sets_.begin(), end = discontinuous_space_sets_.end();
-        it != end; ++it) {
-      SpaceSetMap* set = *it;
-      if (set->Test(obj)) {
-        return set;
+    for (const auto& space_set : discontinuous_space_sets_) {
+      if (space_set->Test(obj)) {
+        return space_set;
       }
     }
     return NULL;
diff --git a/runtime/gc/accounting/mod_union_table.cc b/runtime/gc/accounting/mod_union_table.cc
index 3bbc381..4865219 100644
--- a/runtime/gc/accounting/mod_union_table.cc
+++ b/runtime/gc/accounting/mod_union_table.cc
@@ -36,54 +36,6 @@
 namespace gc {
 namespace accounting {
 
-class MarkIfReachesAllocspaceVisitor {
- public:
-  explicit MarkIfReachesAllocspaceVisitor(Heap* const heap, accounting::SpaceBitmap* bitmap)
-    : heap_(heap),
-      bitmap_(bitmap) {
-  }
-
-  // Extra parameters are required since we use this same visitor signature for checking objects.
-  void operator()(const Object* obj, const Object* ref, const MemberOffset& /* offset */,
-                  bool /* is_static */) const {
-    // TODO: Optimize?
-    // TODO: C++0x auto
-    const std::vector<space::ContinuousSpace*>& spaces = heap_->GetContinuousSpaces();
-    typedef std::vector<space::ContinuousSpace*>::const_iterator It;
-    for (It cur = spaces.begin(); cur != spaces.end(); ++cur) {
-      if ((*cur)->IsDlMallocSpace() && (*cur)->Contains(ref)) {
-        bitmap_->Set(obj);
-        break;
-      }
-    }
-  }
-
- private:
-  Heap* const heap_;
-  accounting::SpaceBitmap* const bitmap_;
-};
-
-class ModUnionVisitor {
- public:
-  explicit ModUnionVisitor(Heap* const heap, accounting::SpaceBitmap* bitmap)
-    : heap_(heap),
-      bitmap_(bitmap) {
-  }
-
-  void operator()(const Object* obj) const
-      SHARED_LOCKS_REQUIRED(Locks::heap_bitmap_lock_,
-                            Locks::mutator_lock_) {
-    DCHECK(obj != NULL);
-    // We don't have an early exit since we use the visitor pattern, an early exit should
-    // significantly speed this up.
-    MarkIfReachesAllocspaceVisitor visitor(heap_, bitmap_);
-    collector::MarkSweep::VisitObjectReferences(obj, visitor);
-  }
- private:
-  Heap* const heap_;
-  accounting::SpaceBitmap* const bitmap_;
-};
-
 class ModUnionClearCardSetVisitor {
  public:
   explicit ModUnionClearCardSetVisitor(ModUnionTable::CardSet* const cleared_cards)
@@ -237,29 +189,23 @@
 void ModUnionTableReferenceCache::Verify() {
   // Start by checking that everything in the mod union table is marked.
   Heap* heap = GetHeap();
-  typedef SafeMap<const byte*, std::vector<const Object*> >::const_iterator It;
-  typedef std::vector<const Object*>::const_iterator It2;
-  for (It it = references_.begin(), end = references_.end(); it != end; ++it) {
-    for (It2 it_ref = it->second.begin(), end_ref = it->second.end(); it_ref != end_ref;
-        ++it_ref ) {
-      CHECK(heap->IsLiveObjectLocked(*it_ref));
+  for (const std::pair<const byte*, std::vector<const Object*> >& it : references_) {
+    for (const Object* ref : it.second) {
+      CHECK(heap->IsLiveObjectLocked(ref));
     }
   }
 
   // Check the references of each clean card which is also in the mod union table.
   CardTable* card_table = heap->GetCardTable();
-  for (It it = references_.begin(); it != references_.end(); ++it) {
-    const byte* card = &*it->first;
+  for (const std::pair<const byte*, std::vector<const Object*> > & it : references_) {
+    const byte* card = it.first;
     if (*card == CardTable::kCardClean) {
-      std::set<const Object*> reference_set;
-      for (It2 itr = it->second.begin(); itr != it->second.end(); ++itr) {
-        reference_set.insert(*itr);
-      }
+      std::set<const Object*> reference_set(it.second.begin(), it.second.end());
       ModUnionCheckReferences visitor(this, reference_set);
       uintptr_t start = reinterpret_cast<uintptr_t>(card_table->AddrFromCard(card));
       uintptr_t end = start + CardTable::kCardSize;
-      space::ContinuousSpace* space =
-          heap->FindContinuousSpaceFromObject(reinterpret_cast<Object*>(start), false);
+      auto* space = heap->FindContinuousSpaceFromObject(reinterpret_cast<Object*>(start), false);
+      DCHECK(space != nullptr);
       SpaceBitmap* live_bitmap = space->GetLiveBitmap();
       live_bitmap->VisitMarkedRange(start, end, visitor);
     }
@@ -268,24 +214,20 @@
 
 void ModUnionTableReferenceCache::Dump(std::ostream& os) {
   CardTable* card_table = heap_->GetCardTable();
-  typedef std::set<byte*>::const_iterator It;
   os << "ModUnionTable cleared cards: [";
-  for (It it = cleared_cards_.begin(); it != cleared_cards_.end(); ++it) {
-    byte* card = *it;
-    uintptr_t start = reinterpret_cast<uintptr_t>(card_table->AddrFromCard(card));
+  for (byte* card_addr : cleared_cards_) {
+    uintptr_t start = reinterpret_cast<uintptr_t>(card_table->AddrFromCard(card_addr));
     uintptr_t end = start + CardTable::kCardSize;
     os << reinterpret_cast<void*>(start) << "-" << reinterpret_cast<void*>(end) << ",";
   }
   os << "]\nModUnionTable references: [";
-  typedef SafeMap<const byte*, std::vector<const Object*> >::const_iterator It2;
-  for (It2 it = references_.begin(); it != references_.end(); ++it) {
-    const byte* card = &*it->first;
-    uintptr_t start = reinterpret_cast<uintptr_t>(card_table->AddrFromCard(card));
+  for (const std::pair<const byte*, std::vector<const Object*> >& it : references_) {
+    const byte* card_addr = it.first;
+    uintptr_t start = reinterpret_cast<uintptr_t>(card_table->AddrFromCard(card_addr));
     uintptr_t end = start + CardTable::kCardSize;
     os << reinterpret_cast<void*>(start) << "-" << reinterpret_cast<void*>(end) << "->{";
-    typedef std::vector<const Object*>::const_iterator It3;
-    for (It3 itr = it->second.begin(); itr != it->second.end(); ++itr) {
-      os << reinterpret_cast<const void*>(*itr) << ",";
+    for (const mirror::Object* ref : it.second) {
+      os << reinterpret_cast<const void*>(ref) << ",";
     }
     os << "},";
   }
@@ -298,20 +240,18 @@
   std::vector<const Object*> cards_references;
   ModUnionReferenceVisitor visitor(this, &cards_references);
 
-  typedef std::set<byte*>::iterator It;
-  for (It it = cleared_cards_.begin(), cc_end = cleared_cards_.end(); it != cc_end; ++it) {
-    byte* card = *it;
+  for (const auto& card : cleared_cards_) {
     // Clear and re-compute alloc space references associated with this card.
     cards_references.clear();
     uintptr_t start = reinterpret_cast<uintptr_t>(card_table->AddrFromCard(card));
     uintptr_t end = start + CardTable::kCardSize;
-    SpaceBitmap* live_bitmap =
-        heap->FindContinuousSpaceFromObject(reinterpret_cast<Object*>(start), false)->GetLiveBitmap();
+    auto* space = heap->FindContinuousSpaceFromObject(reinterpret_cast<Object*>(start), false);
+    DCHECK(space != nullptr);
+    SpaceBitmap* live_bitmap = space->GetLiveBitmap();
     live_bitmap->VisitMarkedRange(start, end, visitor);
 
     // Update the corresponding references for the card.
-    // TODO: C++0x auto
-    SafeMap<const byte*, std::vector<const Object*> >::iterator found = references_.find(card);
+    auto found = references_.find(card);
     if (found == references_.end()) {
       if (cards_references.empty()) {
         // No reason to add empty array.
@@ -326,14 +266,11 @@
 }
 
 void ModUnionTableReferenceCache::MarkReferences(collector::MarkSweep* mark_sweep) {
-  // TODO: C++0x auto
   size_t count = 0;
 
-  typedef SafeMap<const byte*, std::vector<const Object*> >::const_iterator It;
-  for (It it = references_.begin(); it != references_.end(); ++it) {
-    typedef std::vector<const Object*>::const_iterator It2;
-    for (It2 it_ref = it->second.begin(); it_ref != it->second.end(); ++it_ref) {
-      mark_sweep->MarkRoot(*it_ref);
+  for (const auto& ref : references_) {
+    for (const auto& obj : ref.second) {
+      mark_sweep->MarkRoot(obj);
       ++count;
     }
   }
@@ -353,38 +290,28 @@
 void ModUnionTableCardCache::MarkReferences(collector::MarkSweep* mark_sweep) {
   CardTable* card_table = heap_->GetCardTable();
   ModUnionScanImageRootVisitor visitor(mark_sweep);
-  typedef std::set<byte*>::const_iterator It;
-  It it = cleared_cards_.begin();
-  It cc_end = cleared_cards_.end();
-  if (it != cc_end) {
-    byte* card = *it;
-    uintptr_t start = reinterpret_cast<uintptr_t>(card_table->AddrFromCard(card));
-    uintptr_t end = start + CardTable::kCardSize;
-    space::ContinuousSpace* cur_space =
-        heap_->FindContinuousSpaceFromObject(reinterpret_cast<Object*>(start), false);
-    accounting::SpaceBitmap* cur_live_bitmap = cur_space->GetLiveBitmap();
-    cur_live_bitmap->VisitMarkedRange(start, end, visitor);
-    for (++it; it != cc_end; ++it) {
-      card = *it;
-      start = reinterpret_cast<uintptr_t>(card_table->AddrFromCard(card));
-      end = start + CardTable::kCardSize;
-      if (UNLIKELY(!cur_space->Contains(reinterpret_cast<Object*>(start)))) {
-        cur_space = heap_->FindContinuousSpaceFromObject(reinterpret_cast<Object*>(start), false);
-        cur_live_bitmap = cur_space->GetLiveBitmap();
-      }
-      cur_live_bitmap->VisitMarkedRange(start, end, visitor);
+  space::ContinuousSpace* space = nullptr;
+  SpaceBitmap* bitmap = nullptr;
+  for (const byte* card_addr : cleared_cards_) {
+    auto start = reinterpret_cast<uintptr_t>(card_table->AddrFromCard(card_addr));
+    auto end = start + CardTable::kCardSize;
+    auto obj_start = reinterpret_cast<Object*>(start);
+    if (UNLIKELY(space == nullptr || !space->Contains(obj_start))) {
+      space = heap_->FindContinuousSpaceFromObject(obj_start, false);
+      DCHECK(space != nullptr);
+      bitmap = space->GetLiveBitmap();
+      DCHECK(bitmap != nullptr);
     }
+    bitmap->VisitMarkedRange(start, end, visitor);
   }
 }
 
 void ModUnionTableCardCache::Dump(std::ostream& os) {
   CardTable* card_table = heap_->GetCardTable();
-  typedef std::set<byte*>::const_iterator It;
   os << "ModUnionTable dirty cards: [";
-  for (It it = cleared_cards_.begin(); it != cleared_cards_.end(); ++it) {
-    byte* card = *it;
-    uintptr_t start = reinterpret_cast<uintptr_t>(card_table->AddrFromCard(card));
-    uintptr_t end = start + CardTable::kCardSize;
+  for (const byte* card_addr : cleared_cards_) {
+    auto start = reinterpret_cast<uintptr_t>(card_table->AddrFromCard(card_addr));
+    auto end = start + CardTable::kCardSize;
     os << reinterpret_cast<void*>(start) << "-" << reinterpret_cast<void*>(end) << ",";
   }
   os << "]";