@@ -69,6 +69,34 @@ if wanted
6969 copy))
7070
7171
72+ ; ; from
73+ ; ; https://stackoverflow.com/questions/11067899/is-there-a-generic-method-for-cloning-clos-objects
74+
75+ ; ; Don't need it to be an object on non standard-classes for this
76+ ; ; project, if so, we can promote it to the old form of being a
77+ ; ; defgeneric.
78+
79+ (defmethod copy-instance ((object standard-object ) &rest initargs &key &allow-other-keys )
80+ " Makes and returns a shallow copy of OBJECT.
81+
82+ An uninitialized object of the same class as OBJECT is allocated by
83+ calling ALLOCATE-INSTANCE. For all slots returned by
84+ CLASS-SLOTS, the returned object has the
85+ same slot values and slot-unbound status as OBJECT.
86+
87+ REINITIALIZE-INSTANCE is called to update the copy with INITARGS."
88+ (let* ((class (class-of object))
89+ (copy (allocate-instance class )))
90+ (dolist (slot (c2mop :class-slots class ))
91+ ; ; moved the mapcar into a let, as allocation wise, CCL
92+ ; ; preformed better this way.
93+ (let ((slot-name (c2mop :slot-definition-name slot)))
94+ (when (slot-boundp object slot-name)
95+ (setf (slot-value copy slot-name)
96+ (slot-value object slot-name)))))
97+ (values
98+ (apply #' reinitialize-instance copy initargs))))
99+
72100; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
73101; ; Numeric Utilities
74102; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
0 commit comments