[climacs-devel] cached grammar

Robert Strandh strandh at labri.fr
Wed Apr 13 04:25:28 UTC 2005


Christophe Rhodes writes:
 > -(defmethod item-equal ((item1 incomplete-item) (item2 incomplete-item))
 > +(defun item-equal (item1 item2)
 > +  (declare (optimize speed))
 >    (and (eq (rule item1) (rule item2))
 > -       (eq (length (parse-trees item1)) (length (parse-trees item2)))
 > -       (every #'parse-tree-equal (parse-trees item1) (parse-trees item2))))
 > +       (do ((trees1 (parse-trees item1) (cdr trees1))
 > +	    (trees2 (parse-trees item2) (cdr trees2)))
 > +	   ((and (null trees1) (null trees2)) t)
 > +	 (when (or (null trees1) (null trees2))
 > +	   (return nil))
 > +	 (when (not (parse-tree-equal (car trees1) (car trees2)))
 > +	   (return nil)))))

Are you sure this is an improvement? If parse-tree-equal is relatively
slow and there is a prefix of the parse trees that are equal but the
length of the two lists is not equal, then many unnecessary tests for
parse-tree-equal are made. 

-- 
Robert Strandh

---------------------------------------------------------------------
Greenspun's Tenth Rule of Programming: any sufficiently complicated C
or Fortran program contains an ad hoc informally-specified bug-ridden
slow implementation of half of Common Lisp.
---------------------------------------------------------------------



More information about the climacs-devel mailing list