IR: Avoid duplication of SwitchInst::findCaseValue(), NFC
authorDuncan P. N. Exon Smith <dexonsmith@apple.com>
Fri, 12 Nov 2021 02:20:52 +0000 (18:20 -0800)
committerDuncan P. N. Exon Smith <dexonsmith@apple.com>
Fri, 12 Nov 2021 19:44:08 +0000 (11:44 -0800)
Change the non-const version of findCaseValue() to forward to the const
version.

llvm/include/llvm/IR/Instructions.h

index 0ef78881c6d7acd08f03f8ccef76b0fe8cf65cce..45984d2d0a727b1a2216a274381308f87dd17dce 100644 (file)
@@ -3515,12 +3515,9 @@ public:
   /// default case iterator to indicate that it is handled by the default
   /// handler.
   CaseIt findCaseValue(const ConstantInt *C) {
-    CaseIt I = llvm::find_if(
-        cases(), [C](CaseHandle &Case) { return Case.getCaseValue() == C; });
-    if (I != case_end())
-      return I;
-
-    return case_default();
+    return CaseIt(
+        this,
+        const_cast<const SwitchInst *>(this)->findCaseValue(C)->getCaseIndex());
   }
   ConstCaseIt findCaseValue(const ConstantInt *C) const {
     ConstCaseIt I = llvm::find_if(cases(), [C](ConstCaseHandle &Case) {