gdb: remove unnecessary local variable in pager_file::puts

Message ID 20250305191347.138960-1-simon.marchi@efficios.com
State New
Headers
Series gdb: remove unnecessary local variable in pager_file::puts |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gdb_build--master-arm success Build passed
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 success Build passed
linaro-tcwg-bot/tcwg_gdb_check--master-arm success Test passed
linaro-tcwg-bot/tcwg_gdb_check--master-aarch64 success Test passed

Commit Message

Simon Marchi March 5, 2025, 7:13 p.m. UTC
  The lineptr variable isn't really necessary, we can just keep using
linebuffer, since the original value is linebuffer isn't needed.  Remove
lineptr, and fix some comparisons to be explicit.

Change-Id: If2f7df43bf79efd40149e46d5c77f9bc0439f879
---
 gdb/utils.c | 33 +++++++++++++++------------------
 1 file changed, 15 insertions(+), 18 deletions(-)


base-commit: 6594ca4a99dabbebd70c0748dee61d8b3a373336
  

Comments

Tom Tromey March 5, 2025, 8:23 p.m. UTC | #1
>>>>> "Simon" == Simon Marchi <simon.marchi@efficios.com> writes:

Simon> The lineptr variable isn't really necessary, we can just keep using
Simon> linebuffer, since the original value is linebuffer isn't needed.  Remove
Simon> lineptr, and fix some comparisons to be explicit.

Could have just renamed the parameter ;-)

This is ok, thanks.
Approved-By: Tom Tromey <tom@tromey.com>

Tom
  
Simon Marchi March 6, 2025, 4:15 p.m. UTC | #2
On 2025-03-05 15:23, Tom Tromey wrote:
>>>>>> "Simon" == Simon Marchi <simon.marchi@efficios.com> writes:
> 
> Simon> The lineptr variable isn't really necessary, we can just keep using
> Simon> linebuffer, since the original value is linebuffer isn't needed.  Remove
> Simon> lineptr, and fix some comparisons to be explicit.
> 
> Could have just renamed the parameter ;-)

Yeah I considered it but I preferred the name `linebuffer` :).

> This is ok, thanks.
> Approved-By: Tom Tromey <tom@tromey.com>

Thanks, pushed.

Simon
  

Patch

diff --git a/gdb/utils.c b/gdb/utils.c
index 9842bfc8be0f..3d216e1ba13a 100644
--- a/gdb/utils.c
+++ b/gdb/utils.c
@@ -1636,8 +1636,6 @@  begin_line (void)
 void
 pager_file::puts (const char *linebuffer)
 {
-  const char *lineptr;
-
   gdb_assert (linebuffer != nullptr);
 
   /* Don't do any filtering or wrapping if both are disabled.  */
@@ -1669,8 +1667,7 @@  pager_file::puts (const char *linebuffer)
      when this is necessary; prompt user for new page when this is
      necessary.  */
 
-  lineptr = linebuffer;
-  while (*lineptr)
+  while (*linebuffer != '\0')
     {
       /* Possible new page.  Note that PAGINATION_DISABLED_FOR_COMMAND
 	 might be set during this loop, so we must continue to check
@@ -1680,39 +1677,39 @@  pager_file::puts (const char *linebuffer)
 	  && lines_printed >= lines_allowed)
 	prompt_for_continue ();
 
-      while (*lineptr && *lineptr != '\n')
+      while (*linebuffer != '\0' && *linebuffer != '\n')
 	{
 	  int skip_bytes;
 
 	  /* Print a single line.  */
-	  if (*lineptr == '\t')
+	  if (*linebuffer == '\t')
 	    {
 	      m_wrap_buffer.push_back ('\t');
 	      /* Shifting right by 3 produces the number of tab stops
 		 we have already passed, and then adding one and
 		 shifting left 3 advances to the next tab stop.  */
 	      chars_printed = ((chars_printed >> 3) + 1) << 3;
-	      lineptr++;
+	      linebuffer++;
 	    }
-	  else if (*lineptr == '\033'
-		   && skip_ansi_escape (lineptr, &skip_bytes))
+	  else if (*linebuffer == '\033'
+		   && skip_ansi_escape (linebuffer, &skip_bytes))
 	    {
-	      m_wrap_buffer.append (lineptr, skip_bytes);
+	      m_wrap_buffer.append (linebuffer, skip_bytes);
 	      /* Note that we don't consider this a character, so we
 		 don't increment chars_printed here.  */
-	      lineptr += skip_bytes;
+	      linebuffer += skip_bytes;
 	    }
-	  else if (*lineptr == '\r')
+	  else if (*linebuffer == '\r')
 	    {
-	      m_wrap_buffer.push_back (*lineptr);
+	      m_wrap_buffer.push_back (*linebuffer);
 	      chars_printed = 0;
-	      lineptr++;
+	      linebuffer++;
 	    }
 	  else
 	    {
-	      m_wrap_buffer.push_back (*lineptr);
+	      m_wrap_buffer.push_back (*linebuffer);
 	      chars_printed++;
-	      lineptr++;
+	      linebuffer++;
 	    }
 
 	  if (chars_printed >= chars_per_line)
@@ -1786,13 +1783,13 @@  pager_file::puts (const char *linebuffer)
 	    }
 	}
 
-      if (*lineptr == '\n')
+      if (*linebuffer == '\n')
 	{
 	  chars_printed = 0;
 	  wrap_here (0); /* Spit out chars, cancel further wraps.  */
 	  lines_printed++;
 	  m_stream->puts ("\n");
-	  lineptr++;
+	  linebuffer++;
 	}
     }