From: Nikodemus Siivola Date: Sun, 20 Jan 2013 11:28:43 +0000 (+0200) Subject: better initial value for LOOP variables of-type CHARACTER X-Git-Url: http://repo.macrolet.net/gitweb/?a=commitdiff_plain;h=91ab8b634b86ea43a985d35c7fa58e7432f1a28a;p=sbcl.git better initial value for LOOP variables of-type CHARACTER --- diff --git a/NEWS b/NEWS index fb73ea8..1ccdb41 100644 --- a/NEWS +++ b/NEWS @@ -1,5 +1,7 @@ ;;;; -*- coding: utf-8; fill-column: 78 -*- changes relative to sbcl-1.1.3: + * optimization: LOOP expressions using "of-type character" have slightly + more efficient expansions. * bug fix: very long (or infinite) constant lists in DOLIST do not result in very long compile times or heap exhaustion anymore. (lp#1095488) * bug fix: `#3(1) is read as #(1 1 1), not as #(1). (lp#1095918) diff --git a/src/code/loop.lisp b/src/code/loop.lisp index e4ad5e9..726abee 100644 --- a/src/code/loop.lisp +++ b/src/code/loop.lisp @@ -925,6 +925,8 @@ code to be loaded. (let ((etype (sb!kernel:type-*-to-t (sb!kernel:array-type-specialized-element-type ctype)))) (make-array 0 :element-type (sb!kernel:type-specifier etype)))))) + ((sb!xc:typep #\x data-type) + #\x) (t nil))) diff --git a/tests/loop.pure.lisp b/tests/loop.pure.lisp index 9e6a2db..5cd85f3 100644 --- a/tests/loop.pure.lisp +++ b/tests/loop.pure.lisp @@ -13,6 +13,8 @@ (in-package "CL-USER") +(load "compiler-test-util.lisp") + ;;; The bug reported by Alexei Dejneka on sbcl-devel 2001-09-03 ;;; is fixed now. (assert (equal (let ((hash (make-hash-table))) @@ -273,3 +275,13 @@ (assert (= 32640 (loop for i to 255 sum i into sum of-type fixnum finally (return sum))))) + +(with-test (:name :of-type-character-init) + ;; The intention here is to if we initialize C to NIL before iteration start + ;; by looking for tell-tale types such as (OR NULL CHARACTER). ...not the + ;; most robust test ever, no. + (let* ((fun (compile nil `(lambda (x) + (loop for c of-type character in x + collect (char-code c))))) + (consts (ctu:find-code-constants fun :type '(or symbol list)))) + (assert (or (null consts) (equal 'character consts)))))