public inbox for binutils-cvs@sourceware.org
help / color / mirror / Atom feed
* [binutils-gdb] x86: de-duplicate sub-architecture strings accumulation
@ 2022-07-05  6:40 Jan Beulich
  0 siblings, 0 replies; only message in thread
From: Jan Beulich @ 2022-07-05  6:40 UTC (permalink / raw)
  To: bfd-cvs

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=8180707f9042b70a14b55cb147724c323e6042b6

commit 8180707f9042b70a14b55cb147724c323e6042b6
Author: Jan Beulich <jbeulich@suse.com>
Date:   Tue Jul 5 08:39:43 2022 +0200

    x86: de-duplicate sub-architecture strings accumulation
    
    Introduce a helper function to replace 4 instances of similar code. Use
    reconcat() to cover the previously explicit free().

Diff:
---
 gas/config/tc-i386.c | 52 ++++++++++++++--------------------------------------
 1 file changed, 14 insertions(+), 38 deletions(-)

diff --git a/gas/config/tc-i386.c b/gas/config/tc-i386.c
index 288bbe19929..e3501b2728a 100644
--- a/gas/config/tc-i386.c
+++ b/gas/config/tc-i386.c
@@ -2847,6 +2847,16 @@ check_cpu_arch_compatible (const char *name ATTRIBUTE_UNUSED,
 #endif
 }
 
+static void
+extend_cpu_sub_arch_name (const char *name)
+{
+  if (cpu_sub_arch_name)
+    cpu_sub_arch_name = reconcat (cpu_sub_arch_name, cpu_sub_arch_name,
+				  name, (const char *) NULL);
+  else
+    cpu_sub_arch_name = xstrdup (name);
+}
+
 static void
 set_cpu_arch (int dummy ATTRIBUTE_UNUSED)
 {
@@ -2895,16 +2905,7 @@ set_cpu_arch (int dummy ATTRIBUTE_UNUSED)
 
 	      if (!cpu_flags_equal (&flags, &cpu_arch_flags))
 		{
-		  if (cpu_sub_arch_name)
-		    {
-		      char *name = cpu_sub_arch_name;
-		      cpu_sub_arch_name = concat (name,
-						  cpu_arch[j].name,
-						  (const char *) NULL);
-		      free (name);
-		    }
-		  else
-		    cpu_sub_arch_name = xstrdup (cpu_arch[j].name);
+		  extend_cpu_sub_arch_name (string);
 		  cpu_arch_flags = flags;
 		  cpu_arch_isa_flags = flags;
 		}
@@ -2928,15 +2929,7 @@ set_cpu_arch (int dummy ATTRIBUTE_UNUSED)
 					   cpu_noarch[j].flags);
 		if (!cpu_flags_equal (&flags, &cpu_arch_flags))
 		  {
-		    if (cpu_sub_arch_name)
-		      {
-			char *name = cpu_sub_arch_name;
-			cpu_sub_arch_name = concat (name, string,
-						    (const char *) NULL);
-			free (name);
-		      }
-		    else
-		      cpu_sub_arch_name = xstrdup (string);
+		    extend_cpu_sub_arch_name (string);
 		    cpu_arch_flags = flags;
 		    cpu_arch_isa_flags = flags;
 		  }
@@ -13403,16 +13396,7 @@ md_parse_option (int c, const char *arg)
 
 		  if (!cpu_flags_equal (&flags, &cpu_arch_flags))
 		    {
-		      if (cpu_sub_arch_name)
-			{
-			  char *name = cpu_sub_arch_name;
-			  cpu_sub_arch_name = concat (name,
-						      cpu_arch[j].name,
-						      (const char *) NULL);
-			  free (name);
-			}
-		      else
-			cpu_sub_arch_name = xstrdup (cpu_arch[j].name);
+		      extend_cpu_sub_arch_name (cpu_arch[j].name);
 		      cpu_arch_flags = flags;
 		      cpu_arch_isa_flags = flags;
 		    }
@@ -13436,15 +13420,7 @@ md_parse_option (int c, const char *arg)
 					       cpu_noarch[j].flags);
 		    if (!cpu_flags_equal (&flags, &cpu_arch_flags))
 		      {
-			if (cpu_sub_arch_name)
-			  {
-			    char *name = cpu_sub_arch_name;
-			    cpu_sub_arch_name = concat (arch,
-							(const char *) NULL);
-			    free (name);
-			  }
-			else
-			  cpu_sub_arch_name = xstrdup (arch);
+			extend_cpu_sub_arch_name (arch);
 			cpu_arch_flags = flags;
 			cpu_arch_isa_flags = flags;
 		      }


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-07-05  6:40 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-05  6:40 [binutils-gdb] x86: de-duplicate sub-architecture strings accumulation Jan Beulich

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).