From b3d4ff9f6affca1d8897a62913e7e197739170a4 Mon Sep 17 00:00:00 2001
From: dtc <dtc>
Date: Fri, 5 Jun 1998 02:55:30 +0000
Subject: [PATCH] Replace the PCL-INSTANCE-P macro by a compiler transform so
 that the test can be optimised away when the result is known, such as is
 typically the case during slot access within methods, and define a respective
 function for use by interpreted code.

---
 pcl/cmu-low.lisp | 28 ++++++++++++++++++++++++++--
 1 file changed, 26 insertions(+), 2 deletions(-)

diff --git a/pcl/cmu-low.lisp b/pcl/cmu-low.lisp
index d8e7618fe..5b5b08368 100644
--- a/pcl/cmu-low.lisp
+++ b/pcl/cmu-low.lisp
@@ -127,8 +127,32 @@
 ;;;
 (defmacro std-instance-p (x)
   `(kernel:%instancep ,x))
-(defmacro pcl-instance-p (x)
-  `(typep (kernel:layout-of ,x) 'wrapper))
+
+;;; PCL-INSTANCE-P is implemented via a compiler transform so that the
+;;; test can be optimised away when the result is known, such as is
+;;; typically the case during slot access within methods, see
+;;; get-slots-or-nil below.
+
+(in-package "C")
+
+(defknown pcl::pcl-instance-p (t) boolean
+  (movable foldable flushable explicit-check))
+
+(deftransform pcl::pcl-instance-p ((object))
+  (let* ((otype (continuation-type object))
+	 (std-obj (specifier-type 'pcl::std-object)))
+    (cond
+      ;; Flush tests whose result is known at compile time.
+      ((csubtypep otype std-obj) 't)
+      ((not (types-intersect otype std-obj)) 'nil)
+      (t
+       `(typep (kernel:layout-of object) 'pcl::wrapper)))))
+
+(in-package "PCL")
+
+;;; Definition for interpreted code.
+(defun pcl-instance-p (x)
+  (typep (kernel:layout-of x) 'wrapper))
 
 
 ;;; We define this as STANDARD-INSTANCE, since we're going to clobber the
-- 
GitLab