From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Paul Eggert Newsgroups: gmane.emacs.devel Subject: Re: Change a while loop into do while Date: Sat, 31 Dec 2016 09:20:31 -0800 Organization: UCLA Computer Science Department Message-ID: References: <87lgv2km1x.fsf@gmail.com> <83shp4gx9g.fsf@gnu.org> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------654F10E4118D46637CC7687F" X-Trace: blaine.gmane.org 1483204869 11621 195.159.176.226 (31 Dec 2016 17:21:09 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sat, 31 Dec 2016 17:21:09 +0000 (UTC) User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.5.1 Cc: emacs-devel@gnu.org To: Eli Zaretskii , Chris Gregory Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sat Dec 31 18:21:05 2016 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cNNL1-0001hS-L1 for ged-emacs-devel@m.gmane.org; Sat, 31 Dec 2016 18:20:59 +0100 Original-Received: from localhost ([::1]:44970 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cNNL6-0004r0-9U for ged-emacs-devel@m.gmane.org; Sat, 31 Dec 2016 12:21:04 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:48938) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cNNKw-0004pY-UQ for emacs-devel@gnu.org; Sat, 31 Dec 2016 12:20:55 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cNNKv-00057A-VA for emacs-devel@gnu.org; Sat, 31 Dec 2016 12:20:54 -0500 Original-Received: from zimbra.cs.ucla.edu ([131.179.128.68]:50616) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cNNKr-00055l-3q; Sat, 31 Dec 2016 12:20:49 -0500 Original-Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id 17679160063; Sat, 31 Dec 2016 09:20:44 -0800 (PST) Original-Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id ESUvIpAhHHWH; Sat, 31 Dec 2016 09:20:44 -0800 (PST) Original-Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id 08A91160073; Sat, 31 Dec 2016 09:20:44 -0800 (PST) X-Virus-Scanned: amavisd-new at zimbra.cs.ucla.edu Original-Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id 7-ElMU91Tdh0; Sat, 31 Dec 2016 09:20:43 -0800 (PST) Original-Received: from [192.168.1.9] (unknown [47.153.178.162]) by zimbra.cs.ucla.edu (Postfix) with ESMTPSA id CE6A3160063; Sat, 31 Dec 2016 09:20:43 -0800 (PST) In-Reply-To: <83shp4gx9g.fsf@gnu.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 131.179.128.68 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:211032 Archived-At: This is a multi-part message in MIME format. --------------654F10E4118D46637CC7687F Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit > From: Chris Gregory > Date: Mon, 26 Dec 2016 22:55:54 -0600 > > This patch changes string_from_display_spec (a static function in > xdisp.c) to use a do while loop instead of a while loop. The > precondition is checked by the if statement and is redundant in the > first iteration. This redundancy is now removed. The indenting for 'do-while' wasn't using the usual GNU style, and while fixing that I noticed that the code could be further simplified, so I installed the attached further patch. --------------654F10E4118D46637CC7687F Content-Type: text/x-diff; name="0001-src-xdisp.c-string_from_display_spec-Simplify.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="0001-src-xdisp.c-string_from_display_spec-Simplify.patch" >From c48d410258353bc1ed8ec658ab69da2d67e1e8ea Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Sat, 31 Dec 2016 09:13:38 -0800 Subject: [PATCH] * src/xdisp.c (string_from_display_spec): Simplify. --- src/xdisp.c | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/src/xdisp.c b/src/xdisp.c index 45a04ca..aced59e 100644 --- a/src/xdisp.c +++ b/src/xdisp.c @@ -1250,26 +1250,18 @@ default_line_pixel_height (struct window *w) static Lisp_Object string_from_display_spec (Lisp_Object spec) { - if (CONSP (spec)) + if (VECTORP (spec)) { - do { - if (STRINGP (XCAR (spec))) - return XCAR (spec); - spec = XCDR (spec); - } while (CONSP (spec)); + for (ptrdiff_t i = 0; i < ASIZE (spec); i++) + if (STRINGP (AREF (spec, i))) + return AREF (spec, i); } - else if (VECTORP (spec)) + else { - ptrdiff_t i; - - for (i = 0; i < ASIZE (spec); i++) - { - if (STRINGP (AREF (spec, i))) - return AREF (spec, i); - } - return Qnil; + for (; CONSP (spec); spec = XCDR (spec)) + if (STRINGP (XCAR (spec))) + return XCAR (spec); } - return spec; } -- 2.7.4 --------------654F10E4118D46637CC7687F--