(require 'seq)
(require 'subr-x)
-(eval-when-compile (require 'cl-lib))
+(require 'cl-lib)
(defvar memory-report--type-size (make-hash-table))
value)
total))
+;; All cl-defstruct types.
+(cl-defmethod memory-report--object-size-1 (counted (value cl-structure-object))
+ (let ((struct-type (type-of value)))
+ (apply #'+
+ (memory-report--size 'vector)
+ (mapcar (lambda (slot)
+ (if (eq (car slot) 'cl-tag-slot)
+ 0
+ (memory-report--object-size
+ counted
+ (cl-struct-slot-value struct-type (car slot) value))))
+ (cl-struct-slot-info struct-type)))))
+
(defun memory-report--format (bytes)
(setq bytes (/ bytes 1024.0))
(let ((units '("KiB" "MiB" "GiB" "TiB")))
(vector string string))
124))))
+(ert-deftest memory-report-sizes-structs ()
+ (cl-defstruct memory-report-test-struct
+ (item0 nil)
+ (item1 nil))
+ (let ((s (make-memory-report-test-struct :item0 "hello" :item1 "world")))
+ (should (= (memory-report-object-size s)
+ 90))))
+
(provide 'memory-report-tests)
;;; memory-report-tests.el ends here