optimize insertionsort: one less loop variable, one more addition, unconditional first step

svn: r17227
This commit is contained in:
Eli Barzilay 2009-12-06 09:11:47 +00:00
parent 24fff3e4cc
commit 1a12497bc1

View File

@ -76,14 +76,16 @@ doing these checks.
(loop a1 b1 c1)))))))))
(define-syntax-rule (copying-insertionsort Alo Blo n)
(let iloop ([i 0] [A Alo])
;; n is never 0
(begin (set! Blo (ref Alo))
(let iloop ([i 1])
(when (i< i n)
(let ([ref-i (ref A)])
(let ([ref-i (ref (i+ Alo i))])
(let jloop ([j (i+ Blo i)])
(let ([ref-j-1 (ref (i- j 1))])
(if (and (i< Blo j) (<? ref-i ref-j-1))
(begin (set! j ref-j-1) (jloop (i- j 1)))
(begin (set! j ref-i) (iloop (i+ i 1) (i+ A 1))))))))))
(begin (set! j ref-i) (iloop (i+ i 1)))))))))))
(define (copying-mergesort Alo Blo n)
(cond