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: Tino Calancha
Subject: Re: [PATCH] ash, lsh: Avoid code duplication
Date: Tue, 22 Nov 2016 11:17:24 +0900
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.50 (gnu/linux)

Eli Zaretskii <address@hidden> writes:

>> +Lisp_Object
>> +ash_lsh_impl (register Lisp_Object value, Lisp_Object count, bool lsh)
>
> static Lisp_Object
> ash_lsh_impl (register Lisp_Object value, Lisp_Object count, bool lsh)
>
>> diff --git a/src/lisp.h b/src/lisp.h
>> index e087828..c48c2c8 100644
>> --- 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);
>> +Lisp_Object ash_lsh_impl (Lisp_Object, Lisp_Object, bool);
>
> No need to declare it here, as it is a static function used only in
> the file in which it is defined.

Thank you very much.
Here is the updated patch:

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
>From 5b21b3ab846203c329710685433f16a78f1699f3 Mon Sep 17 00:00:00 2001
From: Tino Calancha <address@hidden>
Date: Tue, 22 Nov 2016 11:12:51 +0900
Subject: [PATCH] ash, lsh avoid code duplication

* src/data.c (ash_lsh_impl): New function.
(ash, lsh): Use it.
---
 src/data.c | 36 +++++++++++++++---------------------
 1 file changed, 15 insertions(+), 21 deletions(-)

diff --git a/src/data.c b/src/data.c
index d221db4..61b5da8 100644
--- a/src/data.c
+++ b/src/data.c
@@ -2924,11 +2924,8 @@ usage: (logxor &rest INTS-OR-MARKERS)  */)
   return arith_driver (Alogxor, nargs, args);
 }
 
-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)
+static Lisp_Object
+ash_lsh_impl (register Lisp_Object value, Lisp_Object count, bool lsh)
 {
   register Lisp_Object val;
 
@@ -2940,32 +2937,29 @@ In this case, the sign bit is duplicated.  */)
   else if (XINT (count) > 0)
     XSETINT (val, XUINT (value) << XFASTINT (count));
   else if (XINT (count) <= -EMACS_INT_WIDTH)
-    XSETINT (val, XINT (value) < 0 ? -1 : 0);
+    XSETINT (val, lsh ? 0 : XINT (value) < 0 ? -1 : 0);
   else
-    XSETINT (val, XINT (value) >> -XINT (count));
+    XSETINT (val, lsh ? XUINT (value) >> -XINT (count) : \
+                        XINT (value) >> -XINT (count));
   return val;
 }
 
+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, false);
+}
+
 DEFUN ("lsh", Flsh, Slsh, 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, zeros are shifted in on the left.  */)
   (register Lisp_Object value, Lisp_Object count)
 {
-  register Lisp_Object val;
-
-  CHECK_NUMBER (value);
-  CHECK_NUMBER (count);
-
-  if (XINT (count) >= EMACS_INT_WIDTH)
-    XSETINT (val, 0);
-  else if (XINT (count) > 0)
-    XSETINT (val, XUINT (value) << XFASTINT (count));
-  else if (XINT (count) <= -EMACS_INT_WIDTH)
-    XSETINT (val, 0);
-  else
-    XSETINT (val, XUINT (value) >> -XINT (count));
-  return val;
+  return ash_lsh_impl (value, count, true);
 }
 
 DEFUN ("1+", Fadd1, Sadd1, 1, 1, 0,
-- 
2.10.2

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

In GNU Emacs 26.0.50.1 (x86_64-pc-linux-gnu, GTK+ Version 3.22.3)
 of 2016-11-22 built on calancha-pc
Repository revision: f9946cab7e30a7e01806c4d6273a9251a4504c16




reply via email to

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