Browse files

Avoid unnecessary work in :alias and :refer candidate search

- The :alias expression no longer iterates through (all-ns) if no
  aliased symbols are present in the body

- The :refer expression no longer iterates through every var of every
  namespace; (ns-publics ns) returns a map keyed by symbols so a simple
  contains? will do the same work

While these optimizations offer minor performance gains, the gain in
code clarity also merits their inclusion.
  • Loading branch information...
1 parent 5c101f7 commit d80d4a32939d712be259619aaaebcca6fcff743f @guns guns committed Feb 6, 2014
Showing with 7 additions and 8 deletions.
  1. +7 −8 src/slam/hound/regrow.clj
15 src/slam/hound/regrow.clj
@@ -91,16 +91,15 @@
:import (into (ns-import-candidates missing)
(get @search/available-classes-by-last-segment missing))
:alias (set
- (for [ns (all-ns)
- :let [syms-with-alias (get (ns-qualifed-syms body) missing)]
- :when (and (seq syms-with-alias)
- (set/subset? syms-with-alias
- (set (keys (ns-publics ns)))))]
- (ns-name ns)))
+ (let [syms-with-alias (get (ns-qualifed-syms body) missing)]
+ (when (seq syms-with-alias)
+ (for [ns (all-ns)
+ :let [ns-syms (set (keys (ns-publics ns)))]
+ :when (set/subset? syms-with-alias ns-syms)]
+ (ns-name ns)))))
:refer (set
(for [ns (all-ns)
- [sym _] (ns-publics ns)
- :when (= missing sym)]
+ :when (contains? (ns-publics ns) missing)]
(ns-name ns)))))
(defn- filter-excludes

0 comments on commit d80d4a3

Please sign in to comment.