[net.lang.lisp] A fast copy for Franz Lisp

mckay@burdvax.UUCP (07/18/83)

After dinking around with some application program we are developing we noticed
that copying of lists in franz could be made much faster than that version
distributed in the normal franz release (at least that one distributed several
months ago, it may have changed by now). For what its worth:

;-- fcopy : l - a list
;
;       Copies a list structure l, returns a new structure which is
;       equal to l but not eq to l. Uses atom to terminate so will work
;       with lists of the form (-- . c) where c is an atom. This version
;       is substatially faster the the original definition of copy in the
;       franz distribution (see below). Implemented as a toplevel function and
;       a localf help function which does all the work (this gives some speed
;       up in function call for compiled version).
;
;****  Benchmarking tests indicate this version when compiled is about 10 times
;****  faster than the franz system copy (which is double recursive and nice to
;****  read) with (*rset t) and (sstatus translink nil) [slow links] and about
;****  2 times faster with (*rset nil) and (sstatus translink on) [fast links].
;
;  Copyright (c) 1983
;   Donald P McKay, Karl Puder & Herb Jellinek
;   System Development Corporation - A Burroughs Company, R&D, Paoli, PA.
;
;  ...!burdvax!mckay, ...!burdvax!puder, ...!burdvax!hdj

(declare (localf fcopyx))

(defun fcopy (l)(fcopyx l))

(def fcopyx
  (lambda (l)
    (cond ((atom l) l)
	  (t
	   (prog (val ptr)
		   (setq val (cons (fcopyx (car l)) nil)
			 ptr val)
		   begin
		   (setq l (cdr l))
		   (cond ((atom l)(rplacd ptr l) (return val)))
		   (rplacd ptr (cons (fcopyx (car l)) nil))
		   (setq ptr (cdr ptr))
                   (go begin)))
	  )))