emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Simplify internal_catch()


From: Stefan Monnier
Subject: Re: Simplify internal_catch()
Date: Tue, 27 Dec 2016 21:50:21 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1.50 (gnu/linux)

> --- a/src/eval.c
> +++ b/src/eval.c
> @@ -458,7 +458,11 @@ usage: (progn BODY...)  */)
>  void
>  prog_ignore (Lisp_Object body)
>  {
> -  Fprogn (body);
> +  while (CONSP (body))
> +    {
> +      eval_sub (XCAR (body));
> +      body = XCDR (body);
> +    }
>  }

Why bother?  This is not performance-critical code, so the most
important criterion is to make the code clear and reduce redundancy.

> THE DIFF FOR THIS PATCH is in the attachments.

Both patches are identical, right?

> -  struct handler *c = push_handler (tag, CATCHER);
> +  struct handler *c;
> +  Lisp_Object val;
> +
> +  c = push_handler (tag, CATCHER);

Why place the declaration of `val` between the two?  I always strongly prefer
initializing a var directly in its declaration so that you simply cannot
refer to it in an uninitialized state.  Even more so for a variable
which is never modified afterwards.

>    if (! sys_setjmp (c->jmp))
> -    {
> -      Lisp_Object val = func (arg);
> -      clobbered_eassert (handlerlist == c);
> -      handlerlist = handlerlist->next;
> -      return val;
> -    }
> +    /* Call FUNC.  */
> +    val = func (arg);
>    else
> -    { /* Throw works by a longjmp that comes right here.  */
> -      Lisp_Object val = handlerlist->val;
> -      clobbered_eassert (handlerlist == c);
> -      handlerlist = handlerlist->next;
> -      return val;
> -    }
> +    /* Throw works by a longjmp that comes right here.  */
> +    val = handlerlist->val;
> +  clobbered_eassert (handlerlist == c);
> +  handlerlist = handlerlist->next;
> +  return val;

Right: sharing the tail is a good idea, thanks.


        Stefan




reply via email to

[Prev in Thread] Current Thread [Next in Thread]