From fb52dba011ae1785654f2f3a3cedef2119789dc2 Mon Sep 17 00:00:00 2001 From: Simon Atanasyan Date: Thu, 10 Apr 2014 06:02:49 +0000 Subject: [PATCH] Use range-based for loops. No functionality change. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@205953 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Support/YAMLTraits.cpp | 41 ++++++++++++++++------------------------- 1 file changed, 16 insertions(+), 25 deletions(-) diff --git a/lib/Support/YAMLTraits.cpp b/lib/Support/YAMLTraits.cpp index 005a8107748..f46f140abd8 100644 --- a/lib/Support/YAMLTraits.cpp +++ b/lib/Support/YAMLTraits.cpp @@ -158,10 +158,9 @@ void Input::endMapping() { MapHNode *MN = dyn_cast_or_null(CurrentNode); if (!MN) return; - for (MapHNode::NameToNode::iterator i = MN->Mapping.begin(), - End = MN->Mapping.end(); i != End; ++i) { - if (!MN->isValidKey(i->first())) { - setError(i->second, Twine("unknown key '") + i->first() + "'"); + for (const auto &NN : MN->Mapping) { + if (!MN->isValidKey(NN.first())) { + setError(NN.second, Twine("unknown key '") + NN.first() + "'"); break; } } @@ -255,9 +254,8 @@ bool Input::bitSetMatch(const char *Str, bool) { return false; if (SequenceHNode *SQ = dyn_cast(CurrentNode)) { unsigned Index = 0; - for (std::vector::iterator i = SQ->Entries.begin(), - End = SQ->Entries.end(); i != End; ++i) { - if (ScalarHNode *SN = dyn_cast(*i)) { + for (HNode *N : SQ->Entries) { + if (ScalarHNode *SN = dyn_cast(N)) { if (SN->value().equals(Str)) { BitValuesUsed[Index] = true; return true; @@ -319,9 +317,8 @@ Input::HNode *Input::createHNodes(Node *N) { return new ScalarHNode(N, KeyStr); } else if (SequenceNode *SQ = dyn_cast(N)) { SequenceHNode *SQHNode = new SequenceHNode(N); - for (SequenceNode::iterator i = SQ->begin(), End = SQ->end(); i != End; - ++i) { - HNode *Entry = this->createHNodes(i); + for (Node &SN : *SQ) { + HNode *Entry = this->createHNodes(&SN); if (EC) break; SQHNode->Entries.push_back(Entry); @@ -329,9 +326,8 @@ Input::HNode *Input::createHNodes(Node *N) { return SQHNode; } else if (MappingNode *Map = dyn_cast(N)) { MapHNode *mapHNode = new MapHNode(N); - for (MappingNode::iterator i = Map->begin(), End = Map->end(); i != End; - ++i) { - ScalarNode *KeyScalar = dyn_cast(i->getKey()); + for (KeyValueNode &KVN : *Map) { + ScalarNode *KeyScalar = dyn_cast(KVN.getKey()); StringStorage.clear(); StringRef KeyStr = KeyScalar->getValue(StringStorage); if (!StringStorage.empty()) { @@ -341,7 +337,7 @@ Input::HNode *Input::createHNodes(Node *N) { memcpy(Buf, &StringStorage[0], Len); KeyStr = StringRef(Buf, Len); } - HNode *ValueHNode = this->createHNodes(i->getValue()); + HNode *ValueHNode = this->createHNodes(KVN.getValue()); if (EC) break; mapHNode->Mapping[KeyStr] = ValueHNode; @@ -356,9 +352,8 @@ Input::HNode *Input::createHNodes(Node *N) { } bool Input::MapHNode::isValidKey(StringRef Key) { - for (SmallVectorImpl::iterator i = ValidKeys.begin(), - End = ValidKeys.end(); i != End; ++i) { - if (Key.equals(*i)) + for (const char *K : ValidKeys) { + if (Key.equals(K)) return true; } return false; @@ -373,17 +368,13 @@ bool Input::canElideEmptySequence() { } Input::MapHNode::~MapHNode() { - for (MapHNode::NameToNode::iterator i = Mapping.begin(), End = Mapping.end(); - i != End; ++i) { - delete i->second; - } + for (auto &N : Mapping) + delete N.second; } Input::SequenceHNode::~SequenceHNode() { - for (std::vector::iterator i = Entries.begin(), End = Entries.end(); - i != End; ++i) { - delete *i; - } + for (HNode *N : Entries) + delete N; } -- 2.11.0