better implementation of BitVector.setAndSignExtend()
authoradam <adam@megacz.com>
Mon, 3 Nov 2008 09:28:06 +0000 (10:28 +0100)
committeradam <adam@megacz.com>
Mon, 3 Nov 2008 09:28:06 +0000 (10:28 +0100)
src/edu/berkeley/fleet/api/BitVector.java

index b43ec72..b84b17f 100644 (file)
@@ -33,11 +33,8 @@ public class BitVector {
     /** copy the low-order bits of the argument into this BitVector and sign extend; returns <tt>this</tt> */
     public BitVector setAndSignExtend(long value) {
         if (immutable) throw new RuntimeException("attempt to modify an immutable BitVector");
-        for(int i=0; i<Math.min(length(), 64); i++)
-            set(i, ((value >>> i) & 1L) != 0);
-        if (value < 0)
-            for(int i=64; i<length(); i++)
-                set(i, true);
+        for(int i=0; i<length(); i++)
+            set(i, i<64 ? (((value >>> i) & 1L) != 0) : value<0 ? true : false);
         return this;
     }