summaryrefslogtreecommitdiff
path: root/src/data.c
diff options
context:
space:
mode:
authorTino Calancha <tino.calancha@gmail.com>2016-11-27 12:22:25 +0900
committerTino Calancha <tino.calancha@gmail.com>2016-11-27 12:22:25 +0900
commit416adda38521c6246f77877c57843264fa4ae711 (patch)
tree84e276770bc8110bc7115019be36eddd6cfde9cd /src/data.c
parent4478cf0ac80b774075c0473d9d4625d1f2918998 (diff)
downloademacs-416adda38521c6246f77877c57843264fa4ae711.tar.gz
ash, lsh avoid code duplication
See discussion in: https://lists.gnu.org/archive/html/emacs-devel/2016-11/msg00469.html * src/data.c (ash_lsh_impl): New function. (ash, lsh): Use it.
Diffstat (limited to 'src/data.c')
-rw-r--r--src/data.c36
1 files changed, 15 insertions, 21 deletions
diff --git a/src/data.c b/src/data.c
index d221db429d1..61b5da8b5b6 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,