public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH, trivial, 1/3] Simplify loop in pp_write_text_as_dot_label_to_stream
@ 2016-04-04 12:14 Tom de Vries
  0 siblings, 0 replies; only message in thread
From: Tom de Vries @ 2016-04-04 12:14 UTC (permalink / raw)
  To: GCC Patches

[-- Attachment #1: Type: text/plain, Size: 303 bytes --]

Hi,

this patch simplifies the loop structure in 
pp_write_text_as_dot_label_to_stream:
- it rewrites the while loop into a for loop
- it factors common code out of the switch cases.

No functional changes.

Bootstrapped and reg-tested on x86_64.

Will commit to stage1 trunk as trivial.

Thanks,
- Tom

[-- Attachment #2: 0001-Simplify-loop-in-pp_write_text_as_dot_label_to_stream.patch --]
[-- Type: text/x-patch, Size: 1466 bytes --]

Simplify loop in pp_write_text_as_dot_label_to_stream

2016-04-04  Tom de Vries  <tom@codesourcery.com>

	* pretty-print.c (pp_write_text_as_dot_label_to_stream): Simplify loop
	structure.

---
 gcc/pretty-print.c | 23 ++++++++++++++---------
 1 file changed, 14 insertions(+), 9 deletions(-)

diff --git a/gcc/pretty-print.c b/gcc/pretty-print.c
index acb89e6..f6e4b43 100644
--- a/gcc/pretty-print.c
+++ b/gcc/pretty-print.c
@@ -159,20 +159,20 @@ pp_write_text_as_dot_label_to_stream (pretty_printer *pp, bool for_record)
   const char *p = text;
   FILE *fp = pp_buffer (pp)->stream;
 
-  while (*p)
+  for (;*p; p++)
     {
+      bool escape_char;
       switch (*p)
 	{
 	/* Print newlines as a left-aligned newline.  */
 	case '\n':
-	  fputs ("\\l\\\n", fp);
+	  fputs ("\\l", fp);
+	  escape_char = true;
 	  break;
 
 	/* A pipe is only special for record-shape nodes.  */
 	case '|':
-	  if (for_record)
-	    fputc ('\\', fp);
-	  fputc (*p, fp);
+	  escape_char = for_record;
 	  break;
 
 	/* The following characters always have to be escaped
@@ -183,13 +183,18 @@ pp_write_text_as_dot_label_to_stream (pretty_printer *pp, bool for_record)
 	case '>':
 	case '"':
 	case ' ':
-	  fputc ('\\', fp);
-	  /* fall through */
+	  escape_char = true;
+	  break;
+
 	default:
-	  fputc (*p, fp);
+	  escape_char = false;
 	  break;
 	}
-      p++;
+
+      if (escape_char)
+	fputc ('\\', fp);
+
+      fputc (*p, fp);
     }
 
   pp_clear_output_area (pp);

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

only message in thread, other threads:[~2016-04-04 12:14 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-04-04 12:14 [PATCH, trivial, 1/3] Simplify loop in pp_write_text_as_dot_label_to_stream Tom de Vries

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