Permalink
Browse files

remove duplicate keyword emit code

keywords are emitted with precomputed hash values except when using
:emit-constants which had its own keyword emit function.

moved duplicate code into emits-keyword
  • Loading branch information...
Thomas Heller authored and swannodette committed Jul 29, 2014
1 parent 98866a2 commit ce8688c8aedce73f03de05ed6f290e00bc4f7ccf
Showing with 20 additions and 22 deletions.
  1. +20 −22 src/clj/cljs/compiler.clj
View
@@ -195,23 +195,27 @@
(let [[_ flags pattern] (re-find #"^(?:\(\?([idmsux]*)\))?(.*)" (str x))]
(emits \/ (.replaceAll (re-matcher #"/" pattern) "\\\\/") \/ flags))))
(defn emits-keyword [kw]
(let [ns (namespace kw)
name (name kw)]
(emits "new cljs.core.Keyword(")
(emit-constant ns)
(emits ",")
(emit-constant name)
(emits ",")
(emit-constant (if ns
(str ns "/" name)
name))
(emits ",")
(emit-constant (hash kw))
(emits ")")))
(defmethod emit-constant clojure.lang.Keyword [x]
(if (-> @env/*compiler* :opts :emit-constants)
(let [value (-> @env/*compiler* ::ana/constant-table x)]
(emits "cljs.core." value))
(let [ns (namespace x)
name (name x)]
(emits "new cljs.core.Keyword(")
(emit-constant ns)
(emits ",")
(emit-constant name)
(emits ",")
(emit-constant (if ns
(str ns "/" name)
name))
(emits ",")
(emit-constant (hash x))
(emits ")"))))
(emits-keyword x)
))
(defmethod emit-constant clojure.lang.Symbol [x]
(let [ns (namespace x)
@@ -1077,15 +1081,9 @@
(doseq [[keyword value] table]
(let [ns (namespace keyword)
name (name keyword)]
(emits "cljs.core." value " = new cljs.core.Keyword(")
(emit-constant ns)
(emits ",")
(emit-constant name)
(emits ",")
(emit-constant (if ns
(str ns "/" name)
name))
(emits ");\n"))))
(emits "cljs.core." value " = ")
(emits-keyword keyword)
(emits ";\n"))))
(defn emit-constants-table-to-file [table dest]
(with-open [out ^java.io.Writer (io/make-writer dest {})]

0 comments on commit ce8688c

Please sign in to comment.