public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH v2 1/2] [gdb/tui] Simplify tui_puts_internal
@ 2023-06-09  9:18 Tom de Vries
  2023-06-09  9:18 ` [PATCH v2 2/2] [gdb/tui] Handle unicode chars in prompt Tom de Vries
  2023-06-09 14:35 ` [PATCH v2 1/2] [gdb/tui] Simplify tui_puts_internal Tom Tromey
  0 siblings, 2 replies; 8+ messages in thread
From: Tom de Vries @ 2023-06-09  9:18 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

Simplify tui_puts_internal by using continue, as per this [1] coding standard
rule, making the function more readable and easier to understand.

No functional changes.

Tested on x86_64-linux.

[1] https://llvm.org/docs/CodingStandards.html#use-early-exits-and-continue-to-simplify-code
---
 gdb/tui/tui-io.c | 39 ++++++++++++++++++++-------------------
 1 file changed, 20 insertions(+), 19 deletions(-)

diff --git a/gdb/tui/tui-io.c b/gdb/tui/tui-io.c
index 908cb834e4c..8cb68d12408 100644
--- a/gdb/tui/tui-io.c
+++ b/gdb/tui/tui-io.c
@@ -523,36 +523,37 @@ tui_puts_internal (WINDOW *w, const char *string, int *height)
 
   while ((c = *string++) != 0)
     {
-      if (c == '\n')
-	saw_nl = true;
-
       if (c == '\1' || c == '\2')
 	{
 	  /* Ignore these, they are readline escape-marking
 	     sequences.  */
+	  continue;
 	}
-      else
+
+      if (c == '\033')
 	{
-	  if (c == '\033')
+	  size_t bytes_read = apply_ansi_escape (w, string - 1);
+	  if (bytes_read > 0)
 	    {
-	      size_t bytes_read = apply_ansi_escape (w, string - 1);
-	      if (bytes_read > 0)
-		{
-		  string = string + bytes_read - 1;
-		  continue;
-		}
+	      string = string + bytes_read - 1;
+	      continue;
 	    }
-	  do_tui_putc (w, c);
+	}
 
-	  if (height != nullptr)
-	    {
-	      int col = getcurx (w);
-	      if (col <= prev_col)
-		++*height;
-	      prev_col = col;
-	    }
+      if (c == '\n')
+	saw_nl = true;
+
+      do_tui_putc (w, c);
+
+      if (height != nullptr)
+	{
+	  int col = getcurx (w);
+	  if (col <= prev_col)
+	    ++*height;
+	  prev_col = col;
 	}
     }
+
   if (TUI_CMD_WIN != nullptr && w == TUI_CMD_WIN->handle.get ())
     update_cmdwin_start_line ();
   if (saw_nl)

base-commit: 30711c89cc7dcd2bd4ea772b2f5dc639c5b1cfcc
-- 
2.35.3


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

end of thread, other threads:[~2023-06-15  9:41 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-09  9:18 [PATCH v2 1/2] [gdb/tui] Simplify tui_puts_internal Tom de Vries
2023-06-09  9:18 ` [PATCH v2 2/2] [gdb/tui] Handle unicode chars in prompt Tom de Vries
2023-06-09 14:40   ` Tom Tromey
2023-06-09 15:39   ` Tom Tromey
2023-06-12 15:19     ` Tom de Vries
2023-06-12 18:44       ` Tom Tromey
2023-06-15  9:42         ` Tom de Vries
2023-06-09 14:35 ` [PATCH v2 1/2] [gdb/tui] Simplify tui_puts_internal Tom Tromey

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