From 17ed473db0bc1759965667f975d89d9c01dda34b Mon Sep 17 00:00:00 2001 From: David Nolen Date: Sun, 20 May 2012 20:46:35 -0400 Subject: [PATCH] * src/clj/cljs/compiler.clj: simpler optimization of keyword invoke --- src/clj/cljs/compiler.clj | 5 +++++ src/cljs/cljs/core.cljs | 9 +++++++++ 2 files changed, 14 insertions(+) diff --git a/src/clj/cljs/compiler.clj b/src/clj/cljs/compiler.clj index 7e4c84f87c..3aaa03dac2 100644 --- a/src/clj/cljs/compiler.clj +++ b/src/clj/cljs/compiler.clj @@ -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) @@ -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)) diff --git a/src/cljs/cljs/core.cljs b/src/cljs/cljs/core.cljs index cb86d9f3ae..71debb5889 100644 --- a/src/cljs/cljs/core.cljs +++ b/src/cljs/cljs/core.cljs @@ -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