From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Barry Margolin Newsgroups: gmane.emacs.help Subject: Re: Optimising Elisp code Date: Fri, 05 Oct 2018 10:28:27 -0400 Organization: A noiseless patient Spider Message-ID: References: <638fb7dc-6fc5-4645-8793-97a00038a3a8@googlegroups.com> NNTP-Posting-Host: blaine.gmane.org X-Trace: blaine.gmane.org 1538749709 23049 195.159.176.226 (5 Oct 2018 14:28:29 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Fri, 5 Oct 2018 14:28:29 +0000 (UTC) User-Agent: MT-NewsWatcher/3.5.3b3 (Intel Mac OS X) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri Oct 05 16:28:25 2018 Return-path: Envelope-to: geh-help-gnu-emacs@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 1g8R5d-0005tF-Na for geh-help-gnu-emacs@m.gmane.org; Fri, 05 Oct 2018 16:28:25 +0200 Original-Received: from localhost ([::1]:35416 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g8R7j-0000pN-Rr for geh-help-gnu-emacs@m.gmane.org; Fri, 05 Oct 2018 10:30:35 -0400 Original-Path: usenet.stanford.edu!goblin2!goblin.stu.neva.ru!news.uzoreto.com!eternal-september.org!feeder.eternal-september.org!reader02.eternal-september.org!barmar.motzarella.org!.POSTED!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 40 Original-Injection-Info: barmar.motzarella.org; posting-host="b3af9408e0693cb7ec8d628aa90f7626"; logging-data="2129"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18VfSO/3Wf0Kwm6y87SKrUQ" Cancel-Lock: sha1:al8cZct/YvH70WR8Nq5BDki8OsY= Original-Xref: usenet.stanford.edu gnu.emacs.help:223998 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.org gmane.emacs.help:118124 Archived-At: In article <638fb7dc-6fc5-4645-8793-97a00038a3a8@googlegroups.com>, Davin Pearson wrote: > Suppose that you have a function: > > (defun foo () > (bar)) > > And bar is a function that has no side effects and returns 123 then calling > the function code-optimize (the name of my optimisation routine) > > M-x code-optimize on the function foo will result in the following defun > > (defun foo () > 123) What you're describing is called inline expansion. AFAIK, the Elisp compiler doesn't do this automatically. You can define bar as a macro -- those HAVE to be expanded at compile time, since that's how they work. You can also define an inline function using defsubst. From the Elisp manual: An inline function works just like an ordinary function except for one thing: when you compile a call to the function, the function's definition is open-coded into the caller. Making a function inline makes explicit calls run faster. But it also has disadvantages. For one thing, it reduces flexibility; if you change the definition of the function, calls already inlined still use the old definition until you recompile them. There are more caveats given in the documentation. -- Barry Margolin, barmar@alum.mit.edu Arlington, MA *** PLEASE post questions in newsgroups, not directly to me ***