branch: externals/emacs-gc-stats
commit 048af820a7f08fe59ca84e6e78c8a254613ab3ec
Author: Ihor Radchenko <yanta...@posteo.net>
Commit: Ihor Radchenko <yanta...@posteo.net>

    emacs-gc-stats-save-session: Smarter repeated session data save
    
    * emacs-gc-stats.el (emacs-gc-stats-save-session): Overwrite
    previously saved data for the current Emacs session.
---
 emacs-gc-stats.el | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/emacs-gc-stats.el b/emacs-gc-stats.el
index e2697f358f..1c2b091749 100644
--- a/emacs-gc-stats.el
+++ b/emacs-gc-stats.el
@@ -131,11 +131,16 @@ Otherwise, collect symbol."
          (and (file-readable-p emacs-gc-stats-file)
               (with-temp-buffer
                 (insert-file-contents emacs-gc-stats-file)
-                (ignore-errors (read (current-buffer)))))))
+                (ignore-errors (read (current-buffer))))))
+        (session (reverse emacs-gc-stats--data)))
+    ;; remove end data in case if we continue recording.
+    (pop emacs-gc-stats--data)
     (with-temp-file emacs-gc-stats-file
       ;; Override partially saved session.
-      (setf (alist-get (car emacs-gc-stats--data) previous-sessions)
-            (cdr emacs-gc-stats--data))
+      (let ((existing (assoc (car session) previous-sessions)))
+        (if existing
+            (setcdr (cdr existing) (cdr session))
+          (push session previous-sessions)))
       (prin1 previous-sessions (current-buffer)))))
 
 (defun emacs-gc-stats-clear ()

Reply via email to