[llvm] 8b3e1ad - IR: Avoid duplication of SwitchInst::findCaseValue(), NFC
Duncan P. N. Exon Smith via llvm-commits
llvm-commits at lists.llvm.org
Fri Nov 12 11:44:24 PST 2021
Author: Duncan P. N. Exon Smith
Date: 2021-11-12T11:44:08-08:00
New Revision: 8b3e1adf2b4a69b6055dc4e07b4e97817208c904
URL: https://github.com/llvm/llvm-project/commit/8b3e1adf2b4a69b6055dc4e07b4e97817208c904
DIFF: https://github.com/llvm/llvm-project/commit/8b3e1adf2b4a69b6055dc4e07b4e97817208c904.diff
LOG: IR: Avoid duplication of SwitchInst::findCaseValue(), NFC
Change the non-const version of findCaseValue() to forward to the const
version.
Added:
Modified:
llvm/include/llvm/IR/Instructions.h
Removed:
################################################################################
diff --git a/llvm/include/llvm/IR/Instructions.h b/llvm/include/llvm/IR/Instructions.h
index 0ef78881c6d7..45984d2d0a72 100644
--- a/llvm/include/llvm/IR/Instructions.h
+++ b/llvm/include/llvm/IR/Instructions.h
@@ -3515,12 +3515,9 @@ class SwitchInst : public Instruction {
/// 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) {
More information about the llvm-commits
mailing list