Browse files

change `satisfies?` so it takes a third parametr. passing false will

disable JS native hash table lookup. this way if a protocol test
fails, we don't pay when we're going to handle the natives cases
directly anyway.
  • Loading branch information...
1 parent 6662f57 commit eaa18d6add2f2989c26de1dc3caac75292efa18c @swannodette swannodette committed Apr 30, 2013
Showing with 22 additions and 14 deletions.
  1. +22 −14 src/clj/cljs/core.clj
View
36 src/clj/cljs/core.clj
@@ -825,21 +825,29 @@
(defmacro satisfies?
"Returns true if x satisfies the protocol"
- [psym x]
- (let [p (:name (cljs.analyzer/resolve-var (dissoc &env :locals) psym))
- prefix (protocol-prefix p)
- xsym (bool-expr (gensym))
- [part bit] (fast-path-protocols p)
- msym (symbol (core/str "-cljs$lang$protocol_mask$partition" part "$"))]
- `(let [~xsym ~x]
- (if ~xsym
- (if (or ~(if bit `(unsafe-bit-and (. ~xsym ~msym) ~bit))
+ ([psym x] `(satisfies? ~psym ~x true))
+ ([psym x check-native]
+ (let [p (:name
+ (cljs.analyzer/resolve-var
+ (dissoc &env :locals) psym))
+ prefix (protocol-prefix p)
+ xsym (bool-expr (gensym))
+ [part bit] (fast-path-protocols p)
+ msym (symbol
+ (core/str "-cljs$lang$protocol_mask$partition" part "$"))]
+ `(let [~xsym ~x]
+ (if ~xsym
+ (if (or ~(if bit `(unsafe-bit-and (. ~xsym ~msym) ~bit))
~(bool-expr `(. ~xsym ~(symbol (core/str "-" prefix)))))
- true
- (if (coercive-not (. ~xsym ~msym))
- (cljs.core/type_satisfies_ ~psym ~xsym)
- false))
- (cljs.core/type_satisfies_ ~psym ~xsym)))))
+ true
+ ~(if check-native
+ `(if (coercive-not (. ~xsym ~msym))
+ (cljs.core/type_satisfies_ ~psym ~xsym)
+ false)
+ false))
+ ~(if check-native
+ `(cljs.core/type_satisfies_ ~psym ~xsym)
+ false))))))
(defmacro lazy-seq [& body]
`(new cljs.core/LazySeq nil false (fn [] ~@body) nil))

0 comments on commit eaa18d6

Please sign in to comment.