Clearly not necessary from a functional perspective.

However I believe the ordering of these tests will affect JVM 
optimisations. You want to test the common/fast cases first. And the JVM 
does some clever things with caching most recently used lookups, which will 
again behave differently if you test things in different orders.

Benchmarking on realistic workloads would typically be required to 
determine the optimal order.

FWIW I find it odd that the null check is third. This is extremely fast 
(certainly faster than instance checks) and is a very common case given the 
amount of nil usage in idiomatic Clojure code (as an empty seq), so I would 
probably put it first.

On Wednesday, 3 May 2017 11:59:29 UTC+8, Tianxiang Xiong wrote:
>
> Why does `clojure.lang.RT/canSeq` need to check both `ISeq` _and_ 
> `Seqable` when `ISeq <- IPersistentCollection <- Seqable`?
>
> static public boolean canSeq(Object coll){
>     return coll instanceof ISeq
>             || coll instanceof Seqable
>             || coll == null
>             || coll instanceof Iterable
>             || coll.getClass().isArray()
>             || coll instanceof CharSequence
>             || coll instanceof Map;
> }
>
>

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to