emacs-devel
[Top][All Lists]
Advanced

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

Re: "simplifications"


From: Miles Bader
Subject: Re: "simplifications"
Date: Mon, 19 Nov 2007 20:33:47 +0900

David Kastrup <address@hidden> writes:
> Personally, I think that we should make the byte compiler optimize the
> unnecessary binding away.

It'd be nice if it did, though you need to analyze the function to make
sure there are no hidden uses of that binding; in particular, you need
to know if any functions called inside the defsubst might use the
dynamic binding of the defsubst's args.

[I personally think that's a bit silly, and that it would be enough to
just define defsubst as not guaranteeing dynamic bindings of its args,
but as a recall, this has been discussed before, and the current
behavior declared necessary...]

This is one area where lexical binding makes things cheaper:

   ;; -*- lexical-binding: t -*-
   (defsubst lcadr (arg) (car (cdr arg)))
   (defun xxx (x) (lcadr x))

=>

   byte code for xxx:
     args: (x)
    interactive: nil
   0    dup       
   1    cdr       
   2    car       
   3    return    

The "dup" is because stack slot 0 is where argument "x" is kept.
[Since x is only used once, the dup is unnecessary here, but it's
certainly cheaper than varref+varbind.]

-Miles
-- 
80% of success is just showing up.  --Woody Allen




reply via email to

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