From patchwork Mon Apr 4 12:14:16 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom de Vries X-Patchwork-Id: 605857 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3qdrX53Sw1z9s4x for ; Mon, 4 Apr 2016 22:14:44 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=lHJvcRIb; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=kdqn6wh4HG9dq193OF2mnS9L8771Clcr/Xzh+sxLLvld4qoQJi l3MZlk0Iuhc3cU/w1SKkopxkf8H0iqslvRhMamqT92CXUKLPZWgQI4arnrNXLwPQ MdXQQTQ12FqtvzRiowtXZMewmwy9xEaaflVkr7qJIcT6FO9KncazY1YuA= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to :from:subject:message-id:date:mime-version:content-type; s= default; bh=/0ytqAdYsFrGus425KwGcV1Ihr0=; b=lHJvcRIb6Ilc7gZu6R2e i7boFCA6y2OYkuJ7LIdkakY9WFJo+gwA3g6eG8MXutVmh02X8syqFXq0a9MkGOu5 mwg6bHIbgrs4Oz/IlvDisvtovj1YevHtLYUVCvQKZVfop1iLCoXPL4U44FRCz78c veVbZaukiJVCsffSxoBBzgg= Received: (qmail 33556 invoked by alias); 4 Apr 2016 12:14:38 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 33528 invoked by uid 89); 4 Apr 2016 12:14:35 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.0 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=Hx-languages-length:1728 X-HELO: relay1.mentorg.com Received: from relay1.mentorg.com (HELO relay1.mentorg.com) (192.94.38.131) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Mon, 04 Apr 2016 12:14:25 +0000 Received: from nat-ies.mentorg.com ([192.94.31.2] helo=SVR-IES-FEM-01.mgc.mentorg.com) by relay1.mentorg.com with esmtp id 1an3Of-0002Fz-Ti from Tom_deVries@mentor.com for gcc-patches@gcc.gnu.org; Mon, 04 Apr 2016 05:14:22 -0700 Received: from [127.0.0.1] (137.202.0.76) by SVR-IES-FEM-01.mgc.mentorg.com (137.202.0.104) with Microsoft SMTP Server id 14.3.224.2; Mon, 4 Apr 2016 13:14:20 +0100 To: GCC Patches From: Tom de Vries Subject: [PATCH, trivial, 1/3] Simplify loop in pp_write_text_as_dot_label_to_stream Message-ID: <57025A98.4060107@mentor.com> Date: Mon, 4 Apr 2016 14:14:16 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.6.0 MIME-Version: 1.0 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 Simplify loop in pp_write_text_as_dot_label_to_stream 2016-04-04 Tom de Vries * 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);