Given
(let [c (char 110)]
(case c \n (println "lol")))
If I run decompile
from https://clojars.org/com.clojure-goes-fast/clj-java-decompiler
I get the following output:
public final class json$fn__15103 extends AFunction {
public static final Object const__2;
public static final Var const__3;
public static final Var const__4;
public static Object invokeStatic() {
final char G__15104;
final char c = G__15104 = RT.charCast(110L);
switch (Util.hash(G__15104)) {
case 110: {
if (Util.equiv((Object)G__15104, json$fn__15103.const__2)) {
return ((IFn)json$fn__15103.const__3.getRawRoot()).invoke("lol");
}
break;
}
}
throw new IllegalArgumentException((String)((IFn)json$fn__15103.const__4.getRawRoot()).invoke("No matching clause: ", G__15104));
}
@Override
public Object invoke() {
return invokeStatic();
}
static {
const__2 = 'n';
const__3 = RT.var("clojure.core", "println");
const__4 = RT.var("clojure.core", "str");
}
}
My question is (given that this decompilation is correct) why does the compiler emit the if
test, and more interestingly, is there a way to get rid of it (by means of instructing the compiler?).
It might also be that I should not care about this because the JIT will take care of it for me, but still.
Also, one could argue, I guess, that since we know that the thing I'm case'ing on is a char
there would be no need to do a Util.hash
on it?