[gambit-list] Specialize equal?, eqv?,
and = to eq? when one of the arguments is a fixnum constant.
feeley at iro.umontreal.ca
Mon Aug 22 18:29:04 EDT 2005
On 22-Aug-05, at 5:22 PM, Bradley Lucier wrote:
> You should specialize equal?, eqv?, and = to eq? when one of the
> arguments is a fixnum constant.
> Gambit-list mailing list
> Gambit-list at iro.umontreal.ca
For quite some time the specialisation from eqv? to eq? on eq?-
testable constants (such as symbols, 32 bit fixnums, characters, #t,
#f, etc) is performed by the compiler. I have extended this to equal?.
For example, the following code
(define (f1 x) (if (equal? x 1000000) 'foo 'bar))
(define (f2 x) (if (equal? x 1000000000000000000000) 'foo 'bar))
now expands to
(define f1 (lambda (x) (if ('#<procedure #2 ##eq?> x 1000000) 'foo
(define f2 (lambda (x) (if (equal? x 1000000000000000000000) 'foo
So in compiled code, (equal? x '()) is as fast as (null? x)
Unfortunately the specialization of = to eq? on 32 bit fixnums does
not work, because
(= x 0) != (eq? x 0)
when x is 0.0 .
More information about the Gambit-list