Function: testcover--copy-object1

testcover--copy-object1 is a byte-compiled function defined in testcover.el.gz.

Signature

(testcover--copy-object1 OBJ VECP HASH-TABLE)

Documentation

Make a copy of OBJ, using a HASH-TABLE of objects already copied.

If OBJ is a cons cell, this recursively copies its car and iteratively copies its cdr. When VECP is non-nil, copy vectors as well as conses.

Source Code

;; Defined in /usr/src/emacs/lisp/emacs-lisp/testcover.el.gz
(defun testcover--copy-object1 (obj vecp hash-table)
  "Make a copy of OBJ, using a HASH-TABLE of objects already copied.
If OBJ is a cons cell, this recursively copies its car and
iteratively copies its cdr.  When VECP is non-nil, copy
vectors as well as conses."
  (if (and (atom obj) (or (not vecp) (not (vectorp obj))))
      obj
    (let ((copy (gethash obj hash-table nil)))
      (unless copy
        (cond
         ((consp obj)
          (let* ((rest obj) current)
	    (setq copy (cons nil nil)
                  current copy)
            (while
                (progn
                  (puthash rest current hash-table)
                  (setf (car current)
                        (testcover--copy-object1 (car rest) vecp hash-table))
                  (setq rest (cdr rest))
                  (cond
                   ((atom rest)
                    (setf (cdr current)
                          (testcover--copy-object1 rest vecp hash-table))
                    nil)
                   ((gethash rest hash-table nil)
                    (setf (cdr current) (gethash rest hash-table nil))
                    nil)
                   (t (setq current
                            (setf (cdr current) (cons nil nil)))))))))
         (t ; (and vecp (vectorp obj)) is true due to test in if above.
          (setq copy (copy-sequence obj))
          (puthash obj copy hash-table)
          (dotimes (i (length copy))
            (aset copy i
                  (testcover--copy-object1 (aref copy i) vecp hash-table))))))
      copy)))