Skip to content

Commit 807b8ed

Browse files
committed
Optimize aliases-by-frequencies
1 parent 26c2b46 commit 807b8ed

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

src/refactor_nrepl/ns/libspecs.clj

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,19 @@
1717
distinct))
1818

1919
(defn- aliases-by-frequencies [libspecs]
20-
(->> libspecs
21-
(mapcat aliases) ; => [[str clojure.string] ...]
22-
(sort-by (comp str second))
23-
(group-by first) ; => {str [[str clojure.string] [str clojure.string]] ...}
24-
(map (comp seq frequencies second)) ; => (([[set clojure.set] 4] [set set] 1) ...)
25-
(map (partial sort-by second >)) ; by decreasing frequency
26-
(map (partial map first)) ; drop frequencies
27-
(map (fn [aliases] (list (ffirst aliases) (map second aliases))))
28-
(mapcat identity)
29-
(apply hash-map)))
20+
(let [grouped (->> libspecs
21+
(mapcat aliases) ; => [[str clojure.string] ...]
22+
(sort-by (comp str second))
23+
(group-by first) ; => {str [[str clojure.string] [str clojure.string]] ...}
24+
)]
25+
(into {}
26+
(comp (map (comp seq frequencies second)) ; => (([[set clojure.set] 4] [set set] 1) ...)
27+
(map (partial sort-by second >)) ; by decreasing frequency
28+
(map (partial map first)) ; drop frequencies
29+
(map (fn [aliases]
30+
[(ffirst aliases),
31+
(mapv second aliases)])))
32+
grouped)))
3033

3134
(defn- get-cached-libspec [^File f lang]
3235
(when-let [[ts v] (get-in @cache [(.getAbsolutePath f) lang])]

0 commit comments

Comments
 (0)