public inbox for binutils-cvs@sourceware.org
 help / color / mirror / Atom feed
* [binutils-gdb] cris: sprintf optimisation
@ 2023-08-03 11:51 Alan Modra
  0 siblings, 0 replies; only message in thread
From: Alan Modra @ 2023-08-03 11:51 UTC (permalink / raw)
  To: bfd-cvs

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

commit 75747be51e6d11287e12c4504f2607d36a0edfd2
Author: Alan Modra <amodra@gmail.com>
Date:   Thu Aug 3 12:26:46 2023 +0930

    cris: sprintf optimisation
    
    Since I was poking at cris-dis.c to avoid the sanitizer warning,
    I figure I might as well make use of stpcpy and sprintf return value
    in other places in this file.
    
            * cris-dis.c (format_hex): Use sprintf return value.
            (format_reg): Use stpcpy and sprintf return, avoiding strlen.
            (format_sup_reg): Likewise.

Diff:
---
 opcodes/cris-dis.c | 29 ++++++++++-------------------
 1 file changed, 10 insertions(+), 19 deletions(-)

diff --git a/opcodes/cris-dis.c b/opcodes/cris-dis.c
index 681fccf0dca..27a7003188e 100644
--- a/opcodes/cris-dis.c
+++ b/opcodes/cris-dis.c
@@ -563,13 +563,11 @@ format_hex (unsigned long number,
   /* Truncate negative numbers on >32-bit hosts.  */
   number &= 0xffffffff;
 
-  sprintf (outbuffer, "0x%lx", number);
-
   /* Save this value for the "case" support.  */
   if (TRACE_CASE)
     last_immediate = number;
 
-  return outbuffer + strlen (outbuffer);
+  return outbuffer + sprintf (outbuffer, "0x%lx", number);
 }
 
 /* Format number as decimal into outbuffer.  Parameter signedp says
@@ -588,11 +586,9 @@ format_dec (long number, char *outbuffer, int signedp)
 static char *
 format_reg (struct cris_disasm_data *disdata,
 	    int regno,
-	    char *outbuffer_start,
+	    char *outbuffer,
 	    bool with_reg_prefix)
 {
-  char *outbuffer = outbuffer_start;
-
   if (with_reg_prefix)
     *outbuffer++ = REGISTER_PREFIX_CHAR;
 
@@ -601,31 +597,30 @@ format_reg (struct cris_disasm_data *disdata,
     case 15:
       /* For v32, there is no context in which we output PC.  */
       if (disdata->distype == cris_dis_v32)
-	strcpy (outbuffer, "acr");
+	outbuffer = stpcpy (outbuffer, "acr");
       else
-	strcpy (outbuffer, "pc");
+	outbuffer = stpcpy (outbuffer, "pc");
       break;
 
     case 14:
-      strcpy (outbuffer, "sp");
+      outbuffer = stpcpy (outbuffer, "sp");
       break;
 
     default:
-      sprintf (outbuffer, "r%d", regno);
+      outbuffer += sprintf (outbuffer, "r%d", regno);
       break;
     }
 
-  return outbuffer_start + strlen (outbuffer_start);
+  return outbuffer;
 }
 
 /* Format the name of a support register into outbuffer.  */
 
 static char *
 format_sup_reg (unsigned int regno,
-		char *outbuffer_start,
+		char *outbuffer,
 		bool with_reg_prefix)
 {
-  char *outbuffer = outbuffer_start;
   int i;
 
   if (with_reg_prefix)
@@ -633,15 +628,11 @@ format_sup_reg (unsigned int regno,
 
   for (i = 0; cris_support_regs[i].name != NULL; i++)
     if (cris_support_regs[i].number == regno)
-      {
-	sprintf (outbuffer, "%s", cris_support_regs[i].name);
-	return outbuffer_start + strlen (outbuffer_start);
-      }
+      return stpcpy (outbuffer, cris_support_regs[i].name);
 
   /* There's supposed to be register names covering all numbers, though
      some may be generic names.  */
-  sprintf (outbuffer, "format_sup_reg-BUG");
-  return outbuffer_start + strlen (outbuffer_start);
+  return stpcpy (outbuffer, "format_sup_reg-BUG");
 }
 
 /* Return the length of an instruction.  */

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

only message in thread, other threads:[~2023-08-03 11:51 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-03 11:51 [binutils-gdb] cris: sprintf optimisation Alan Modra

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