all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Shigeru Fukaya <shigeru.fukaya@gmail.com>
To: 17584@debbugs.gnu.org
Subject: bug#17584: 24.3.91; bug of `=' operator optimization
Date: Mon, 26 May 2014 21:48:00 +0900	[thread overview]
Message-ID: <31CF78E0B9F609shigeru.fukaya@gmail.com> (raw)
In-Reply-To: <30CF77C6B5AF54shigeru.fukaya@gmail.com>

The following is a code with a little more optimized than
byte-optimize-predicate.  It can be used by `<', `<=', `>', `>='.

-- Shigeru


(defun byte-optimize-comparison-predicate (form)
  ;; (cmp-op arg1 [[arg2]...])
  (let (constants
        others
        (rest (cdr form)))
    (while rest
      (if (macroexp-const-p (car rest))
          (push (car rest) constants)
        (push (car rest) others))
      (setq rest (cdr rest)))
    (if constants
        (cond
         ;; only constants
         ((null others) (eval form))
         ;; constants satisfy predicate
         ((apply (car form) (nreverse constants)) form)
         ;; always nil
         (t `(progn ,@(nreverse others) nil)))
      ;; no constant
      form)))


(byte-optimize-comparison-predicate '(= 0 a b))         ==> (= 0 a b)
(byte-optimize-comparison-predicate '(= 1 1.0 1))       ==> t
(byte-optimize-comparison-predicate '(= 1 a (f) 2))     ==> (progn a (f) nil)

(byte-optimize-comparison-predicate '(<= 1 a (f) 1.0))  ==> (<= 1 a (f) 1.0)
(byte-optimize-comparison-predicate '(< 1 a (f) 1.0))   ==> (progn a (f) nil)



>>(byte-optimize-form '(lambda (a b) (= a b 0)))
>>==> (lambda (a b) (= a b 0))
>>(byte-optimize-form '(lambda (a b) (= 0 a b)))
>>==> (lambda (a b) (= a 0))
>>
>>- (put '=   'byte-optimizer 'byte-optimize-binary-predicate)
>>+ (put '=   'byte-optimizer 'byte-optimize-predicate)
>
>byte-optimize-predicate is no good, sorry.
>
>-- Shigeru





  reply	other threads:[~2014-05-26 12:48 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-05-25  3:05 bug#17584: 24.3.91; bug of `=' operator optimization Shigeru Fukaya
2014-05-25  3:09 ` Shigeru Fukaya
2014-05-26 12:48   ` Shigeru Fukaya [this message]
2014-05-26 20:54     ` Stefan Monnier

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=31CF78E0B9F609shigeru.fukaya@gmail.com \
    --to=shigeru.fukaya@gmail.com \
    --cc=17584@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.