From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.devel Subject: Re: [PATCH] ash, lsh: Avoid code duplication Date: Mon, 21 Nov 2016 17:57:20 +0200 Message-ID: <83k2bw9673.fsf@gnu.org> References: <87inrg99in.fsf@gmail.com> Reply-To: Eli Zaretskii NNTP-Posting-Host: blaine.gmane.org X-Trace: blaine.gmane.org 1479743909 9158 195.159.176.226 (21 Nov 2016 15:58:29 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Mon, 21 Nov 2016 15:58:29 +0000 (UTC) Cc: emacs-devel@gnu.org To: Tino Calancha Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon Nov 21 16:58:25 2016 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1c8qzA-0001Ep-MT for ged-emacs-devel@m.gmane.org; Mon, 21 Nov 2016 16:58:24 +0100 Original-Received: from localhost ([::1]:50211 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c8qzE-0006HN-4m for ged-emacs-devel@m.gmane.org; Mon, 21 Nov 2016 10:58:28 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:59376) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c8qxz-0005P8-N7 for emacs-devel@gnu.org; Mon, 21 Nov 2016 10:57:12 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1c8qxw-0000qv-Mb for emacs-devel@gnu.org; Mon, 21 Nov 2016 10:57:11 -0500 Original-Received: from fencepost.gnu.org ([2001:4830:134:3::e]:47383) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c8qxw-0000qr-JL; Mon, 21 Nov 2016 10:57:08 -0500 Original-Received: from 84.94.185.246.cable.012.net.il ([84.94.185.246]:3056 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_128_CBC_SHA1:128) (Exim 4.82) (envelope-from ) id 1c8qxw-0002JF-2C; Mon, 21 Nov 2016 10:57:08 -0500 In-reply-to: <87inrg99in.fsf@gmail.com> (message from Tino Calancha on Mon, 21 Nov 2016 23:45:36 +0900) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2001:4830:134:3::e X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:209524 Archived-At: > From: Tino Calancha > Date: Mon, 21 Nov 2016 23:45:36 +0900 > Cc: tino.calancha@gmail.com > > `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.