emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/haskell-mode 1a285fc4c5 2/2: Merge pull request #1857 from


From: ELPA Syncer
Subject: [nongnu] elpa/haskell-mode 1a285fc4c5 2/2: Merge pull request #1857 from Hi-Angel/hashtable-optimization
Date: Mon, 11 Nov 2024 13:00:12 -0500 (EST)

branch: elpa/haskell-mode
commit 1a285fc4c50ca74bb5cd9b2a8c1a46a64a77384a
Merge: 7d4529ac44 a4e246e6f1
Author: Steve Purcell <steve@sanityinc.com>
Commit: GitHub <noreply@github.com>

    Merge pull request #1857 from Hi-Angel/hashtable-optimization
    
    Optimize and simplify `haskell-ds-create-imenu-index` with hashtable
---
 haskell-decl-scan.el | 55 +++++++++++++---------------------------------------
 1 file changed, 14 insertions(+), 41 deletions(-)

diff --git a/haskell-decl-scan.el b/haskell-decl-scan.el
index 2f4ddff2a1..f32515ac6f 100644
--- a/haskell-decl-scan.el
+++ b/haskell-decl-scan.el
@@ -106,6 +106,7 @@
 (require 'haskell-mode)
 (require 'syntax)
 (require 'imenu)
+(require 'subr-x)
 
 (defgroup haskell-decl-scan nil
   "Haskell declaration scanning (`imenu' support)."
@@ -537,11 +538,7 @@ datatypes) in a Haskell file for the `imenu' package."
   ;; These lists are nested using `(INDEX-TITLE . INDEX-ALIST)'.
   (let* ((bird-literate (haskell-ds-bird-p))
          (index-alist '())
-         (index-class-alist '()) ;; Classes
-         (index-var-alist '())   ;; Variables
-         (index-imp-alist '())   ;; Imports
-         (index-inst-alist '())  ;; Instances
-         (index-type-alist '())  ;; Datatypes
+         (imenu (make-hash-table :test 'equal))
          ;; The result we wish to return.
          result)
     (goto-char (point-min))
@@ -557,47 +554,23 @@ datatypes) in a Haskell file for the `imenu' package."
                  (posns (cdr name-posns))
                  (start-pos (car posns))
                  (type (cdr result)))
-                 ;; Place `(name . start-pos)' in the correct alist.
-                 (cl-case type
-                   (variable
-                    (setq index-var-alist
-                          (cl-acons name start-pos index-var-alist)))
-                   (datatype
-                    (setq index-type-alist
-                          (cl-acons name start-pos index-type-alist)))
-                   (class
-                    (setq index-class-alist
-                          (cl-acons name start-pos index-class-alist)))
-                   (import
-                    (setq index-imp-alist
-                          (cl-acons name start-pos index-imp-alist)))
-                   (instance
-                    (setq index-inst-alist
-                          (cl-acons name start-pos index-inst-alist)))))))
+            (puthash type
+                     (cons (cons name start-pos) (gethash type imenu '()))
+                     imenu))))
     ;; Now sort all the lists, label them, and place them in one list.
-    (when index-type-alist
-      (push (cons "Datatypes"
-                  (sort index-type-alist 'haskell-ds-imenu-label-cmp))
-            index-alist))
-    (when index-inst-alist
-      (push (cons "Instances"
-                  (sort index-inst-alist 'haskell-ds-imenu-label-cmp))
-            index-alist))
-    (when index-imp-alist
-      (push (cons "Imports"
-                  (sort index-imp-alist 'haskell-ds-imenu-label-cmp))
-            index-alist))
-    (when index-class-alist
-      (push (cons "Classes"
-                  (sort index-class-alist 'haskell-ds-imenu-label-cmp))
-            index-alist))
-    (when index-var-alist
+    (dolist (type '((datatype . "Datatypes") (instance . "Instances")
+                    (import   . "Imports")   (class    . "Classes")))
+      (when-let ((curr-alist (gethash (car type) imenu)))
+        (push (cons (cdr type)
+                    (sort curr-alist 'haskell-ds-imenu-label-cmp))
+              index-alist)))
+    (when-let ((var-alist (gethash 'variable imenu)))
       (if haskell-decl-scan-bindings-as-variables
           (push (cons "Variables"
-                      (sort index-var-alist 'haskell-ds-imenu-label-cmp))
+                      (sort var-alist 'haskell-ds-imenu-label-cmp))
                 index-alist)
         (setq index-alist (append index-alist
-                                  (sort index-var-alist 
'haskell-ds-imenu-label-cmp)))))
+                                  (sort var-alist 
'haskell-ds-imenu-label-cmp)))))
     ;; Return the alist.
     index-alist))
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]