diff options
author | Stefan Monnier <monnier@iro.umontreal.ca> | 2014-12-22 22:05:46 -0500 |
---|---|---|
committer | Stefan Monnier <monnier@iro.umontreal.ca> | 2014-12-22 22:05:46 -0500 |
commit | ee93d7ad4291a0946efe3197481cfbeff92f29b8 (patch) | |
tree | 4ff0ca7149c5bead965c4e3e49d104af1cf42e1c /lisp/emacs-lisp/eieio.el | |
parent | d4a12e7a9a46bbff2f9c4d59ecc284621634a2e8 (diff) | |
download | emacs-ee93d7ad4291a0946efe3197481cfbeff92f29b8.tar.gz emacs-ee93d7ad4291a0946efe3197481cfbeff92f29b8.tar.bz2 emacs-ee93d7ad4291a0946efe3197481cfbeff92f29b8.zip |
* lisp/emacs-lisp/eieio*.el: Remove "name" field of objects
* lisp/emacs-lisp/eieio-base.el (clone) <eieio-instance-inheritor>:
Use call-next-method.
(eieio-constructor): Rename from `constructor'.
(eieio-persistent-convert-list-to-object): Drop objname.
(eieio-persistent-validate/fix-slot-value): Don't hardcode
eieio--object-num-slots.
(eieio-named): Use a normal slot.
(slot-missing) <eieio-named>: Remove.
(eieio-object-name-string, eieio-object-set-name-string, clone)
<eieio-named>: New methods.
* lisp/emacs-lisp/eieio-core.el (eieio--defalias): Follow aliases.
(eieio--object): Remove `name' field.
(eieio-defclass): Adjust to new convention where constructors don't
take an "object name" any more.
(eieio--defgeneric-init-form, eieio--defmethod): Follow aliases.
(eieio-validate-slot-value, eieio-oset-default)
(eieio-slot-name-index): Don't hardcode eieio--object-num-slots.
(eieio-generic-call-primary-only): Simplify.
* lisp/emacs-lisp/eieio-custom.el (eieio-widget-test): Remove dummy arg.
(eieio-object-value-get): Use eieio-object-set-name-string.
* lisp/emacs-lisp/eieio.el (make-instance): Simplify by not adding an object
name argument.
(eieio-object-name): Use eieio-object-name-string.
(eieio--object-names): New const.
(eieio-object-name-string, eieio-object-set-name-string): Re-implement
using a hashtable rather than a built-in slot.
(eieio-constructor): Rename from `constructor'. Remove `newname' arg.
(clone): Don't mess with the object's "name".
* test/automated/eieio-test-persist.el (persistent-with-objs-slot-subs):
The type FOO-child is the same as FOO.
* test/automated/eieio-tests.el: Remove dummy object names.
Diffstat (limited to 'lisp/emacs-lisp/eieio.el')
-rw-r--r-- | lisp/emacs-lisp/eieio.el | 60 |
1 files changed, 27 insertions, 33 deletions
diff --git a/lisp/emacs-lisp/eieio.el b/lisp/emacs-lisp/eieio.el index f4e1d246011..51b8c3d2b4a 100644 --- a/lisp/emacs-lisp/eieio.el +++ b/lisp/emacs-lisp/eieio.el @@ -144,12 +144,7 @@ In EIEIO, the class' constructor requires a name for use when printing. `make-instance' in CLOS doesn't use names the way Emacs does, so the class is used as the name slot instead when INITARGS doesn't start with a string." - (if (and (car initargs) (stringp (car initargs))) - (apply (class-constructor class) initargs) - (apply (class-constructor class) - (cond ((symbolp class) (symbol-name class)) - (t (format "%S" class))) - initargs))) + (apply (class-constructor class) initargs)) ;;; CLOS methods and generics @@ -279,20 +274,28 @@ variable name of the same name as the slot." If EXTRA, include that in the string returned to represent the symbol." (eieio--check-type eieio-object-p obj) (format "#<%s %s%s>" (symbol-name (eieio--object-class obj)) - (eieio--object-name obj) (or extra ""))) + (eieio-object-name-string obj) (or extra ""))) (define-obsolete-function-alias 'object-name #'eieio-object-name "24.4") -(defun eieio-object-name-string (obj) "Return a string which is OBJ's name." - (eieio--check-type eieio-object-p obj) - (eieio--object-name obj)) +(defconst eieio--object-names (make-hash-table :test #'eq :weakness 'key)) + +;; In the past, every EIEIO object had a `name' field, so we had the two method +;; below "for free". Since this field is very rarely used, we got rid of it +;; and instead we keep it in a weak hash-tables, for those very rare objects +;; that use it. +(defmethod eieio-object-name-string (obj) + "Return a string which is OBJ's name." + (declare (obsolete eieio-named "25.1")) + (or (gethash obj eieio--object-names) + (symbol-name (eieio-object-class obj)))) (define-obsolete-function-alias 'object-name-string #'eieio-object-name-string "24.4") -(defun eieio-object-set-name-string (obj name) +(defmethod eieio-object-set-name-string (obj name) "Set the string which is OBJ's NAME." - (eieio--check-type eieio-object-p obj) + (declare (obsolete eieio-named "25.1")) (eieio--check-type stringp name) - (setf (eieio--object-name obj) name)) + (setf (gethash obj eieio--object-names) name)) (define-obsolete-function-alias 'object-set-name-string 'eieio-object-set-name-string "24.4") @@ -574,20 +577,19 @@ This class is not stored in the `parent' slot of a class vector." (defalias 'standard-class 'eieio-default-superclass) -(defgeneric constructor (class newname &rest slots) +(defgeneric eieio-constructor (class &rest slots) "Default constructor for CLASS `eieio-default-superclass'.") -(defmethod constructor :static - ((class eieio-default-superclass) newname &rest slots) +(define-obsolete-function-alias 'constructor #'eieio-constructor "25.1") + +(defmethod eieio-constructor :static + ((class eieio-default-superclass) &rest slots) "Default constructor for CLASS `eieio-default-superclass'. -NEWNAME is the name to be given to the constructed object. SLOTS are the initialization slots used by `shared-initialize'. This static method is called when an object is constructed. It allocates the vector used to represent an EIEIO object, and then calls `shared-initialize' on that object." (let* ((new-object (copy-sequence (eieio--class-default-object-cache (eieio--class-v class))))) - ;; Update the name for the newly created object. - (setf (eieio--object-name new-object) newname) ;; Call the initialize method on the new object with the slots ;; that were passed down to us. (initialize-instance new-object slots) @@ -715,18 +717,10 @@ first and modify the returned object.") (defmethod clone ((obj eieio-default-superclass) &rest params) "Make a copy of OBJ, and then apply PARAMS." - (let ((nobj (copy-sequence obj)) - (nm (eieio--object-name obj)) - (passname (and params (stringp (car params)))) - (num 1)) - (if params (shared-initialize nobj (if passname (cdr params) params))) - (if (not passname) - (save-match-data - (if (string-match "-\\([0-9]+\\)" nm) - (setq num (1+ (string-to-number (match-string 1 nm))) - nm (substring nm 0 (match-beginning 0)))) - (setf (eieio--object-name nobj) (concat nm "-" (int-to-string num)))) - (setf (eieio--object-name nobj) (car params))) + (let ((nobj (copy-sequence obj))) + (if (stringp (car params)) + (message "Obsolete name %S passed to clone" (pop params))) + (if params (shared-initialize nobj params)) nobj)) (defgeneric destructor (this &rest params) @@ -889,7 +883,7 @@ variable PRINT-FUNCTION. Optional argument NOESCAPE is passed to ;;; Start of automatically extracted autoloads. -;;;### (autoloads nil "eieio-custom" "eieio-custom.el" "6413249ec10091eb7094238637b40e2c") +;;;### (autoloads nil "eieio-custom" "eieio-custom.el" "3a6fffe3af331fe960f967d0da99e8e9") ;;; Generated autoloads from eieio-custom.el (autoload 'customize-object "eieio-custom" "\ @@ -900,7 +894,7 @@ Optional argument GROUP is the sub-group of slots to display. ;;;*** -;;;### (autoloads nil "eieio-opt" "eieio-opt.el" "6f114a48de40212413d2776eedc3ec14") +;;;### (autoloads nil "eieio-opt" "eieio-opt.el" "2ff7d98da3f84c6af5c873ffb781930e") ;;; Generated autoloads from eieio-opt.el (autoload 'eieio-browse "eieio-opt" "\ |