public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] libiberty: d-demangle: use switch instead of if-else
@ 2021-09-30  1:08 Luís Ferreira
  2021-10-03 21:55 ` Jeff Law
  0 siblings, 1 reply; 4+ messages in thread
From: Luís Ferreira @ 2021-09-30  1:08 UTC (permalink / raw)
  To: gcc-patches; +Cc: Luís Ferreira

This patch allows the compiler to efficiently generate jump tables instead of
using if-else-if.

Signed-off-by: Luís Ferreira <contact@lsferreira.net>
---
 libiberty/d-demangle.c | 44 +++++++++++++++++++-----------------------
 1 file changed, 20 insertions(+), 24 deletions(-)

diff --git a/libiberty/d-demangle.c b/libiberty/d-demangle.c
index 3adf7b562d1..9748a925371 100644
--- a/libiberty/d-demangle.c
+++ b/libiberty/d-demangle.c
@@ -774,30 +774,26 @@ dlang_type (string *decl, const char *mangled, struct dlang_info *info)
       return mangled;
     case 'N':
       mangled++;
-      if (*mangled == 'g') /* wild(T) */
-	{
-	  mangled++;
-	  string_append (decl, "inout(");
-	  mangled = dlang_type (decl, mangled, info);
-	  string_append (decl, ")");
-	  return mangled;
-	}
-      else if (*mangled == 'h') /* vector(T) */
-	{
-	  mangled++;
-	  string_append (decl, "__vector(");
-	  mangled = dlang_type (decl, mangled, info);
-	  string_append (decl, ")");
-	  return mangled;
-	}
-      else if (*mangled == 'n') /* typeof(*null) */
-	{
-	  mangled++;
-	  string_append (decl, "typeof(*null)");
-	  return mangled;
-	}
-      else
-	return NULL;
+      switch (*mangled)
+      {
+	case 'g': /* wild(T) */
+	    mangled++;
+	    string_append (decl, "inout(");
+	    mangled = dlang_type (decl, mangled, info);
+	    string_append (decl, ")");
+	    return mangled;
+	case 'h': /* vector(T) */
+	    mangled++;
+	    string_append (decl, "__vector(");
+	    mangled = dlang_type (decl, mangled, info);
+	    string_append (decl, ")");
+	    return mangled;
+	case 'n': /* typeof(*null) */
+	    mangled++;
+	    string_append (decl, "typeof(*null)");
+	    return mangled;
+      }
+      return NULL;
     case 'A': /* dynamic array (T[]) */
       mangled++;
       mangled = dlang_type (decl, mangled, info);
-- 
2.33.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-10-04 14:56 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-30  1:08 [PATCH] libiberty: d-demangle: use switch instead of if-else Luís Ferreira
2021-10-03 21:55 ` Jeff Law
2021-10-04  7:25   ` ibuclaw
2021-10-04 14:56   ` Luís Ferreira

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).