[llvm] r258004 - [TableGen] Use std::find instead of a manual loop. NFC

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Sun Jan 17 00:05:30 PST 2016


Author: ctopper
Date: Sun Jan 17 02:05:30 2016
New Revision: 258004

URL: http://llvm.org/viewvc/llvm-project?rev=258004&view=rev
Log:
[TableGen] Use std::find instead of a manual loop. NFC

Modified:
    llvm/trunk/utils/TableGen/AsmWriterEmitter.cpp

Modified: llvm/trunk/utils/TableGen/AsmWriterEmitter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/AsmWriterEmitter.cpp?rev=258004&r1=258003&r2=258004&view=diff
==============================================================================
--- llvm/trunk/utils/TableGen/AsmWriterEmitter.cpp (original)
+++ llvm/trunk/utils/TableGen/AsmWriterEmitter.cpp Sun Jan 17 02:05:30 2016
@@ -169,16 +169,14 @@ FindUniqueOperandCommands(std::vector<st
 
     // Check to see if we already have 'Command' in UniqueOperandCommands.
     // If not, add it.
-    bool FoundIt = false;
-    for (unsigned idx = 0, e = UniqueOperandCommands.size(); idx != e; ++idx)
-      if (UniqueOperandCommands[idx] == Command) {
-        InstIdxs[i] = idx;
-        InstrsForCase[idx] += ", ";
-        InstrsForCase[idx] += Inst->CGI->TheDef->getName();
-        FoundIt = true;
-        break;
-      }
-    if (!FoundIt) {
+    auto I = std::find(UniqueOperandCommands.begin(),
+                       UniqueOperandCommands.end(), Command);
+    if (I != UniqueOperandCommands.end()) {
+      size_t idx = I - UniqueOperandCommands.begin();
+      InstIdxs[i] = idx;
+      InstrsForCase[idx] += ", ";
+      InstrsForCase[idx] += Inst->CGI->TheDef->getName();
+    } else {
       InstIdxs[i] = UniqueOperandCommands.size();
       UniqueOperandCommands.push_back(std::move(Command));
       InstrsForCase.push_back(Inst->CGI->TheDef->getName());




More information about the llvm-commits mailing list