[TableGen] Use std::find_if and a lambda instead of manual loops.
authorCraig Topper <craig.topper@gmail.com>
Sun, 3 Jan 2016 07:33:36 +0000 (07:33 +0000)
committerCraig Topper <craig.topper@gmail.com>
Sun, 3 Jan 2016 07:33:36 +0000 (07:33 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@256698 91177308-0d34-0410-b5e6-96231b3b80d8

utils/TableGen/AsmMatcherEmitter.cpp

index 2ec65442a330b4689feb541a67739fde6104fbbe..9a4390753c2fb70ff3654194593578d377468b8d 100644 (file)
@@ -503,20 +503,21 @@ struct MatchableInfo {
   /// findAsmOperand - Find the AsmOperand with the specified name and
   /// suboperand index.
   int findAsmOperand(StringRef N, int SubOpIdx) const {
   /// findAsmOperand - Find the AsmOperand with the specified name and
   /// suboperand index.
   int findAsmOperand(StringRef N, int SubOpIdx) const {
-    for (unsigned i = 0, e = AsmOperands.size(); i != e; ++i)
-      if (N == AsmOperands[i].SrcOpName &&
-          SubOpIdx == AsmOperands[i].SubOpIdx)
-        return i;
-    return -1;
+    auto I = std::find_if(AsmOperands.begin(), AsmOperands.end(),
+                          [&](const AsmOperand &Op) {
+                            return Op.SrcOpName == N && Op.SubOpIdx == SubOpIdx;
+                          });
+    return (I != AsmOperands.end()) ? I - AsmOperands.begin() : -1;
   }
 
   /// findAsmOperandNamed - Find the first AsmOperand with the specified name.
   /// This does not check the suboperand index.
   int findAsmOperandNamed(StringRef N) const {
   }
 
   /// findAsmOperandNamed - Find the first AsmOperand with the specified name.
   /// This does not check the suboperand index.
   int findAsmOperandNamed(StringRef N) const {
-    for (unsigned i = 0, e = AsmOperands.size(); i != e; ++i)
-      if (N == AsmOperands[i].SrcOpName)
-        return i;
-    return -1;
+    auto I = std::find_if(AsmOperands.begin(), AsmOperands.end(),
+                          [&](const AsmOperand &Op) {
+                            return Op.SrcOpName == N;
+                          });
+    return (I != AsmOperands.end()) ? I - AsmOperands.begin() : -1;
   }
 
   void buildInstructionResultOperands();
   }
 
   void buildInstructionResultOperands();