all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Paul Eggert <eggert@cs.ucla.edu>
To: Eli Zaretskii <eliz@gnu.org>, Chris Gregory <czipperz@gmail.com>
Cc: emacs-devel@gnu.org
Subject: Re: Change a while loop into do while
Date: Sat, 31 Dec 2016 09:20:31 -0800	[thread overview]
Message-ID: <d36a2438-a45d-a18d-6778-085d1ce3cff0@cs.ucla.edu> (raw)
In-Reply-To: <83shp4gx9g.fsf@gnu.org>

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

> From: Chris Gregory <czipperz@gmail.com>
> 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.

[-- Attachment #2: 0001-src-xdisp.c-string_from_display_spec-Simplify.patch --]
[-- Type: text/x-diff, Size: 1185 bytes --]

From c48d410258353bc1ed8ec658ab69da2d67e1e8ea Mon Sep 17 00:00:00 2001
From: Paul Eggert <eggert@cs.ucla.edu>
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


  reply	other threads:[~2016-12-31 17:20 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-12-27  4:55 Change a while loop into do while Chris Gregory
2016-12-31 11:20 ` Eli Zaretskii
2016-12-31 17:20   ` Paul Eggert [this message]
2016-12-31 18:00     ` Eli Zaretskii
2016-12-31 18:51       ` Paul Eggert
2016-12-31 19:18         ` Eli Zaretskii
2016-12-31 20:56           ` Paul Eggert
2016-12-31 20:59             ` Eli Zaretskii
2016-12-31 18:12     ` Eli Zaretskii
2016-12-31 18:31       ` Eli Zaretskii
2016-12-31 18:47         ` Paul Eggert

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=d36a2438-a45d-a18d-6778-085d1ce3cff0@cs.ucla.edu \
    --to=eggert@cs.ucla.edu \
    --cc=czipperz@gmail.com \
    --cc=eliz@gnu.org \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.