emacs-devel
[Top][All Lists]
Advanced

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

Re: [PATCH] ash, lsh: Avoid code duplication


From: Eli Zaretskii
Subject: Re: [PATCH] ash, lsh: Avoid code duplication
Date: Mon, 21 Nov 2016 17:57:20 +0200

> From: Tino Calancha <address@hidden>
> Date: Mon, 21 Nov 2016 23:45:36 +0900
> Cc: address@hidden
> 
> `ash' and `lsh' show some overlap.
> How about following patch?

With some more work (see below), and if no one objects, why not?

> +Lisp_Object
> +ash_lsh_impl (register Lisp_Object value, Lisp_Object count, int lsh)
                                                                ^^^^^^^
'bool', please.

Also, the function doesn't need to be extern, it should be static.

> -    XSETINT (val, XINT (value) < 0 ? -1 : 0);
> +    XSETINT (val, lsh == 1 ? 0 : XINT (value) < 0 ? -1 : 0);
                     ^^^^^^^^
a.k.a. "lsh ?"

> +DEFUN ("ash", Fash, Sash, 2, 2, 0,
> +       doc: /* Return VALUE with its bits shifted left by COUNT.
> +If COUNT is negative, shifting is actually to the right.
> +In this case, the sign bit is duplicated.  */)
> +  (register Lisp_Object value, Lisp_Object count)
> +{
> +  return ash_lsh_impl (value, count, 0);
                                        ^
'false', please.

> +  return ash_lsh_impl (value, count, 1);
                                        ^
'true', please.

> --- a/src/lisp.h
> +++ b/src/lisp.h
> @@ -602,6 +602,7 @@ extern void char_table_set (Lisp_Object, int, 
> Lisp_Object);
>  /* Defined in data.c.  */
>  extern _Noreturn Lisp_Object wrong_type_argument (Lisp_Object, Lisp_Object);
>  extern _Noreturn void wrong_choice (Lisp_Object, Lisp_Object);
> +extern Lisp_Object ash_lsh_impl (Lisp_Object, Lisp_Object, int);

No need to make it extern, as no other C file uses it.



reply via email to

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