Changeset 4036


Ignore:
Timestamp:
09/23/03 17:09:39 (20 years ago)
Author:
piso
Message:

Optimize for common case of fixnum arg and count.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/j/src/org/armedbear/lisp/ash.java

    r4030 r4036  
    33 *
    44 * Copyright (C) 2003 Peter Graves
    5  * $Id: ash.java,v 1.1 2003-09-23 16:31:03 piso Exp $
     5 * $Id: ash.java,v 1.2 2003-09-23 17:09:39 piso Exp $
    66 *
    77 * This program is free software; you can redistribute it and/or
     
    3636        throws ConditionThrowable
    3737    {
     38        if (first instanceof Fixnum && second instanceof Fixnum) {
     39            int count = ((Fixnum)second).getValue();
     40            if (count == 0)
     41                return first;
     42            long n = ((Fixnum)first).getValue();
     43            if (n == 0)
     44                return first;
     45            if (count < -32) {
     46                // Right shift.
     47                return n >= 0 ? Fixnum.ZERO : Fixnum.MINUS_ONE;
     48            }
     49            if (count <= 32)
     50                return number(count > 0 ? (n << count) : (n >> -count));
     51        }
    3852        BigInteger n;
    3953        if (first instanceof Fixnum)
     
    5064            // is Integer.MIN_VALUE, so...
    5165            if (count == Integer.MIN_VALUE)
    52                 return n.signum() >= 0 ? Fixnum.ZERO : new Fixnum(-1);
     66                return n.signum() >= 0 ? Fixnum.ZERO : Fixnum.MINUS_ONE;
    5367            return number(n.shiftLeft(count));
    5468        }
     
    5872                throw new ConditionThrowable(new LispError("can't represent result of left shift"));
    5973            if (count.signum() < 0)
    60                 return n.signum() >= 0 ? Fixnum.ZERO : new Fixnum(-1);
     74                return n.signum() >= 0 ? Fixnum.ZERO : Fixnum.MINUS_ONE;
    6175            Debug.bug(); // Shouldn't happen.
    6276        }
Note: See TracChangeset for help on using the changeset viewer.