Optimise `LOGCOUNT`

(Olof-Joachim Frahm)
parent 408784b2
......@@ -45,18 +45,18 @@ public final class logcount extends Primitive
// FIXME Optimize fixnum case!
public LispObject execute(LispObject arg)
BigInteger n;
if (arg instanceof Fixnum)
n = ((Fixnum)arg).getBigInteger();
else if (arg instanceof Bignum)
n = ((Bignum)arg).value;
int n;
if (arg instanceof Fixnum) {
int value = ((Fixnum)arg).value;
n = Integer.bitCount(value < 0 ? ~value : value);
} else if (arg instanceof Bignum)
n = ((Bignum)arg).value.bitCount();
return type_error(arg, Symbol.INTEGER);
return Fixnum.getInstance(n.bitCount());
return Fixnum.getInstance(n);
private static final Primitive LOGCOUNT = new logcount();
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment