[llvm] r239023 - [TableGen] Replace a couple if/else chains with a switch. NFC

Craig Topper craig.topper at gmail.com
Thu Jun 4 00:40:16 PDT 2015


Author: ctopper
Date: Thu Jun  4 02:40:16 2015
New Revision: 239023

URL: http://llvm.org/viewvc/llvm-project?rev=239023&view=rev
Log:
[TableGen] Replace a couple if/else chains with a switch. NFC

Modified:
    llvm/trunk/include/llvm/TableGen/Record.h

Modified: llvm/trunk/include/llvm/TableGen/Record.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/TableGen/Record.h?rev=239023&r1=239022&r2=239023&view=diff
==============================================================================
--- llvm/trunk/include/llvm/TableGen/Record.h (original)
+++ llvm/trunk/include/llvm/TableGen/Record.h Thu Jun  4 02:40:16 2015
@@ -752,11 +752,10 @@ public:
 
   int getNumOperands() const override { return 2; }
   Init *getOperand(int i) const override {
-    assert((i == 0 || i == 1) && "Invalid operand id for binary operator");
-    if (i == 0) {
-      return getLHS();
-    } else {
-      return getRHS();
+    switch (i) {
+    default: llvm_unreachable("Invalid operand id for binary operator");
+    case 0: return getLHS();
+    case 1: return getRHS();
     }
   }
 
@@ -808,14 +807,11 @@ public:
 
   int getNumOperands() const override { return 3; }
   Init *getOperand(int i) const override {
-    assert((i == 0 || i == 1 || i == 2) &&
-           "Invalid operand id for ternary operator");
-    if (i == 0) {
-      return getLHS();
-    } else if (i == 1) {
-      return getMHS();
-    } else {
-      return getRHS();
+    switch (i) {
+    default: llvm_unreachable("Invalid operand id for ternary operator");
+    case 0: return getLHS();
+    case 1: return getMHS();
+    case 2: return getRHS();
     }
   }
 





More information about the llvm-commits mailing list