Skip to content

Commit

Permalink
* src/clj/cljs/compiler.clj: simpler optimization of keyword invoke
Browse files Browse the repository at this point in the history
  • Loading branch information
David Nolen authored and David Nolen committed May 21, 2012
1 parent db896b7 commit 17ed473
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/clj/cljs/compiler.clj
Expand Up @@ -689,6 +689,8 @@
(not (-> f :info :dynamic))
(-> f :info :fn-var))
js? (= (-> f :info :ns) 'js)
keyword? (and (= (-> f :op) :constant)
(keyword? (-> f :form)))
[f variadic-invoke]
(if fn?
(let [info (-> f :info)
Expand Down Expand Up @@ -718,6 +720,9 @@
[f nil])]
(emit-wrap env
(cond
keyword?
(emits "(new cljs.core.Keyword(" f ")).call(" (comma-sep (cons "null" args)) ")")

variadic-invoke
(let [mfa (:max-fixed-arity variadic-invoke)]
(emits f "(" (comma-sep (take mfa args))
Expand Down
9 changes: 9 additions & 0 deletions src/cljs/cljs/core.cljs
Expand Up @@ -1557,6 +1557,15 @@ reduces them without incurring seq initialization"
([string f start]
(ci-reduce string f start))))

(deftype Keyword [k]
IFn
(invoke [_ coll]
(when (coercive-not= coll nil)
(let [strobj (.-strobj coll)]
(if (nil? strobj)
(-lookup coll k nil)
(aget strobj k))))))

;;hrm
(extend-type js/String
IFn
Expand Down

0 comments on commit 17ed473

Please sign in to comment.