From: Yikai Zhao Date: Sat, 14 Aug 2021 11:46:30 +0000 (+0200) Subject: Fix memory-report counting of vector/hash table sizes X-Git-Tag: emacs-28.0.90~1514 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=adb6c3f1a4cc5ec3d26bfb2311dfc87b965153a0;p=emacs.git 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 --- diff --git a/lisp/emacs-lisp/memory-report.el b/lisp/emacs-lisp/memory-report.el index 1125dde4055..aee2a0079ca 100644 --- a/lisp/emacs-lisp/memory-report.el +++ b/lisp/emacs-lisp/memory-report.el @@ -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) diff --git a/test/lisp/emacs-lisp/memory-report-tests.el b/test/lisp/emacs-lisp/memory-report-tests.el index da5f4f5700f..0c0297b5fce 100644 --- a/test/lisp/emacs-lisp/memory-report-tests.el +++ b/test/lisp/emacs-lisp/memory-report-tests.el @@ -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