#248 typep consing

Stable_release
closed
nobody
None
1
2013-01-12
2013-01-12
stassats
No

Type-of conses a new list for integers and arrays.

(type-of 2) => (INTEGER 2 2)
(type-of "12") => (SIMPLE-ARRAY BASE-CHAR (2))

TYPEP on deftyped types uses
(eq (type-of object) type). It'll never get a chance to succeed for integers.

A test-case which shows consing:

   (deftype foo ()
     'fixnum)

   (defun test (n type)
     (loop for i to n
           count (typep n type)))

   (time (test 100000 'foo))
   real time : 0.143 secs
   run time  : 0.144 secs
   gc count  : 1 times
   consed    : 4798960 bytes

   (time (test 100000 'fixnum))
   real time : 0.033 secs
   run time  : 0.032 secs
   gc count  : 1 times
   consed    : 0 bytes

Discussion

  • I have fixed this as you suggested, removing the EQ case and avoiding all further uses of type-of by introducing new functions that check RATIOP, {SINGLE,DOUBLE...}-FLOAT-P, etc.

     


Anonymous


Cancel   Add attachments