Commits

Aidan Kehoe committed b4715fc

#'byte-optimize-letX; group constant initialisations together in let forms

lisp/ChangeLog addition:

2012-05-14 Aidan Kehoe <kehoea@parhasard.net>

* byte-optimize.el (byte-optimize-letX):
In (let ...) forms, group constant initialisations together, so we
can just dup in the byte code.

Comments (0)

Files changed (2)

+2012-05-14  Aidan Kehoe  <kehoea@parhasard.net>
+
+	* byte-optimize.el (byte-optimize-letX):
+	In (let ...) forms, group constant initialisations together, so we
+	can just dup in the byte code.
+
 2012-05-14  Aidan Kehoe  <kehoea@parhasard.net>
 
 	Update minibuf.el to use #'test-completion, use the generality of

lisp/byte-optimize.el

 	 ;; No bindings
 	 (cons 'progn (cdr (cdr form))))
 	((or (nth 2 form) (nthcdr 3 form))
-	 form)
+	 (if (and (eq 'let (car form)) (> (length (nth 1 form)) 2))
+	     ;; Group constant initialisations together, so we can
+	     ;; just dup in the lap code. Can't group other
+	     ;; initialisations together if they have side-effects,
+	     ;; that would re-order them.
+	     (let ((sort (stable-sort
+			  (copy-list (nth 1 form))
+			  #'< :key #'(lambda (object)
+				       (cond ((atom object)
+					      most-positive-fixnum)
+					     ((null (cadr object))
+					      most-positive-fixnum)
+					     ((byte-compile-trueconstp
+					       (cadr object))
+					      (mod (sxhash (cadr object))
+						   most-positive-fixnum))
+					     (t 0))))))
+	       (if (equal sort (nth 1 form))
+		   form
+		 `(let ,sort ,@(cddr form))))
+	   form))
 	 ;; The body is nil
 	((eq (car form) 'let)
 	 (append '(progn) (mapcar 'car-safe (mapcar 'cdr-safe (nth 1 form)))