Fix memory-report counting of vector/hash table sizes
* lisp/emacs-lisp/memory-report.el (memory-report--object-size-1): Count element values in vectors and hash tables. Copyright-paperwork-exempt: yes
This commit is contained in:
parent
37d48edf6d
commit
adb6c3f1a4
2 changed files with 17 additions and 4 deletions
|
@ -230,8 +230,7 @@ by counted more than once."
|
|||
(let ((total (+ (memory-report--size 'vector)
|
||||
(* (memory-report--size 'object) (length value)))))
|
||||
(cl-loop for elem across value
|
||||
do (setf (gethash elem counted) t)
|
||||
(cl-incf total (memory-report--object-size counted elem)))
|
||||
do (cl-incf total (memory-report--object-size counted elem)))
|
||||
total))
|
||||
|
||||
(cl-defmethod memory-report--object-size-1 (counted (value hash-table))
|
||||
|
@ -239,8 +238,6 @@ by counted more than once."
|
|||
(* (memory-report--size 'object) (hash-table-size value)))))
|
||||
(maphash
|
||||
(lambda (key elem)
|
||||
(setf (gethash key counted) t)
|
||||
(setf (gethash elem counted) t)
|
||||
(cl-incf total (memory-report--object-size counted key))
|
||||
(cl-incf total (memory-report--object-size counted elem)))
|
||||
value)
|
||||
|
|
|
@ -45,6 +45,7 @@
|
|||
|
||||
(should (equal (memory-report-object-size (list 'foo)) 16))
|
||||
|
||||
(should (equal (memory-report-object-size (vector 1 2 3)) 64))
|
||||
(should (equal (memory-report-object-size (vector 1 2 3 4)) 80))
|
||||
|
||||
(should (equal (memory-report-object-size "") 32))
|
||||
|
@ -52,6 +53,21 @@
|
|||
(should (equal (memory-report-object-size (propertize "a" 'face 'foo))
|
||||
81)))
|
||||
|
||||
(ert-deftest memory-report-sizes-vectors ()
|
||||
(should (= (memory-report--object-size
|
||||
(make-hash-table :test #'eq)
|
||||
["long string that should be at least 40 bytes"])
|
||||
108))
|
||||
(let ((string "long string that should be at least 40 bytes"))
|
||||
(should (= (memory-report--object-size
|
||||
(make-hash-table :test #'eq)
|
||||
(vector string))
|
||||
108))
|
||||
(should (= (memory-report--object-size
|
||||
(make-hash-table :test #'eq)
|
||||
(vector string string))
|
||||
124))))
|
||||
|
||||
(provide 'memory-report-tests)
|
||||
|
||||
;;; memory-report-tests.el ends here
|
||||
|
|
Loading…
Add table
Reference in a new issue