From c3c2916151e3e3cfe2a7daeace2541ee0da959f1 Mon Sep 17 00:00:00 2001 From: Carsten Otto Date: Sat, 4 Jul 2015 18:36:08 +0200 Subject: [PATCH] Remove useless math like >> 0. --- .../core/TransactionOutputChanges.java | 8 +++---- .../main/java/org/bitcoinj/core/Utils.java | 22 +++++++++---------- .../store/DatabaseFullPrunedBlockStore.java | 4 ++-- .../store/PostgresFullPrunedBlockStore.java | 2 +- .../bitcoinj/core/FullBlockTestGenerator.java | 2 +- 5 files changed, 19 insertions(+), 19 deletions(-) diff --git a/core/src/main/java/org/bitcoinj/core/TransactionOutputChanges.java b/core/src/main/java/org/bitcoinj/core/TransactionOutputChanges.java index 5de25848..74d63c35 100644 --- a/core/src/main/java/org/bitcoinj/core/TransactionOutputChanges.java +++ b/core/src/main/java/org/bitcoinj/core/TransactionOutputChanges.java @@ -38,7 +38,7 @@ public class TransactionOutputChanges { } public TransactionOutputChanges(InputStream in) throws IOException { - int numOutsCreated = ((in.read() & 0xFF) << 0) | + int numOutsCreated = (in.read() & 0xFF) | ((in.read() & 0xFF) << 8) | ((in.read() & 0xFF) << 16) | ((in.read() & 0xFF) << 24); @@ -46,7 +46,7 @@ public class TransactionOutputChanges { for (int i = 0; i < numOutsCreated; i++) txOutsCreated.add(new UTXO(in)); - int numOutsSpent = ((in.read() & 0xFF) << 0) | + int numOutsSpent = (in.read() & 0xFF) | ((in.read() & 0xFF) << 8) | ((in.read() & 0xFF) << 16) | ((in.read() & 0xFF) << 24); @@ -57,7 +57,7 @@ public class TransactionOutputChanges { public void serializeToStream(OutputStream bos) throws IOException { int numOutsCreated = txOutsCreated.size(); - bos.write(0xFF & (numOutsCreated >> 0)); + bos.write(0xFF & numOutsCreated); bos.write(0xFF & (numOutsCreated >> 8)); bos.write(0xFF & (numOutsCreated >> 16)); bos.write(0xFF & (numOutsCreated >> 24)); @@ -66,7 +66,7 @@ public class TransactionOutputChanges { } int numOutsSpent = txOutsSpent.size(); - bos.write(0xFF & (numOutsSpent >> 0)); + bos.write(0xFF & numOutsSpent); bos.write(0xFF & (numOutsSpent >> 8)); bos.write(0xFF & (numOutsSpent >> 16)); bos.write(0xFF & (numOutsSpent >> 24)); diff --git a/core/src/main/java/org/bitcoinj/core/Utils.java b/core/src/main/java/org/bitcoinj/core/Utils.java index 1b7a76f7..407404b6 100644 --- a/core/src/main/java/org/bitcoinj/core/Utils.java +++ b/core/src/main/java/org/bitcoinj/core/Utils.java @@ -79,21 +79,21 @@ public class Utils { } public static void uint32ToByteArrayBE(long val, byte[] out, int offset) { - out[offset + 0] = (byte) (0xFF & (val >> 24)); + out[offset] = (byte) (0xFF & (val >> 24)); out[offset + 1] = (byte) (0xFF & (val >> 16)); out[offset + 2] = (byte) (0xFF & (val >> 8)); - out[offset + 3] = (byte) (0xFF & (val >> 0)); + out[offset + 3] = (byte) (0xFF & val); } public static void uint32ToByteArrayLE(long val, byte[] out, int offset) { - out[offset + 0] = (byte) (0xFF & (val >> 0)); + out[offset] = (byte) (0xFF & val); out[offset + 1] = (byte) (0xFF & (val >> 8)); out[offset + 2] = (byte) (0xFF & (val >> 16)); out[offset + 3] = (byte) (0xFF & (val >> 24)); } public static void uint64ToByteArrayLE(long val, byte[] out, int offset) { - out[offset + 0] = (byte) (0xFF & (val >> 0)); + out[offset] = (byte) (0xFF & val); out[offset + 1] = (byte) (0xFF & (val >> 8)); out[offset + 2] = (byte) (0xFF & (val >> 16)); out[offset + 3] = (byte) (0xFF & (val >> 24)); @@ -104,14 +104,14 @@ public class Utils { } public static void uint32ToByteStreamLE(long val, OutputStream stream) throws IOException { - stream.write((int) (0xFF & (val >> 0))); + stream.write((int) (0xFF & val)); stream.write((int) (0xFF & (val >> 8))); stream.write((int) (0xFF & (val >> 16))); stream.write((int) (0xFF & (val >> 24))); } public static void int64ToByteStreamLE(long val, OutputStream stream) throws IOException { - stream.write((int) (0xFF & (val >> 0))); + stream.write((int) (0xFF & val)); stream.write((int) (0xFF & (val >> 8))); stream.write((int) (0xFF & (val >> 16))); stream.write((int) (0xFF & (val >> 24))); @@ -187,14 +187,14 @@ public class Utils { } public static long readUint32(byte[] bytes, int offset) { - return ((bytes[offset++] & 0xFFL) << 0) | + return (bytes[offset++] & 0xFFL) | ((bytes[offset++] & 0xFFL) << 8) | ((bytes[offset++] & 0xFFL) << 16) | ((bytes[offset] & 0xFFL) << 24); } public static long readInt64(byte[] bytes, int offset) { - return ((bytes[offset++] & 0xFFL) << 0) | + return (bytes[offset++] & 0xFFL) | ((bytes[offset++] & 0xFFL) << 8) | ((bytes[offset++] & 0xFFL) << 16) | ((bytes[offset++] & 0xFFL) << 24) | @@ -205,10 +205,10 @@ public class Utils { } public static long readUint32BE(byte[] bytes, int offset) { - return ((bytes[offset + 0] & 0xFFL) << 24) | + return ((bytes[offset] & 0xFFL) << 24) | ((bytes[offset + 1] & 0xFFL) << 16) | ((bytes[offset + 2] & 0xFFL) << 8) | - ((bytes[offset + 3] & 0xFFL) << 0); + (bytes[offset + 3] & 0xFFL); } public static int readUint16BE(byte[] bytes, int offset) { @@ -309,7 +309,7 @@ public class Utils { bytes[3] = (byte) size; if (size >= 1) bytes[4] = (byte) ((compact >> 16) & 0xFF); if (size >= 2) bytes[5] = (byte) ((compact >> 8) & 0xFF); - if (size >= 3) bytes[6] = (byte) ((compact >> 0) & 0xFF); + if (size >= 3) bytes[6] = (byte) (compact & 0xFF); return decodeMPI(bytes, true); } diff --git a/core/src/main/java/org/bitcoinj/store/DatabaseFullPrunedBlockStore.java b/core/src/main/java/org/bitcoinj/store/DatabaseFullPrunedBlockStore.java index 512fcf08..50993a3d 100644 --- a/core/src/main/java/org/bitcoinj/store/DatabaseFullPrunedBlockStore.java +++ b/core/src/main/java/org/bitcoinj/store/DatabaseFullPrunedBlockStore.java @@ -667,7 +667,7 @@ public abstract class DatabaseFullPrunedBlockStore implements FullPrunedBlockSto txOutChanges = bos.toByteArray(); } else { int numTxn = undoableBlock.getTransactions().size(); - bos.write((int) (0xFF & (numTxn >> 0))); + bos.write((int) (0xFF & numTxn)); bos.write((int) (0xFF & (numTxn >> 8))); bos.write((int) (0xFF & (numTxn >> 16))); bos.write((int) (0xFF & (numTxn >> 24))); @@ -805,7 +805,7 @@ public abstract class DatabaseFullPrunedBlockStore implements FullPrunedBlockSto StoredUndoableBlock block; if (txOutChanges == null) { int offset = 0; - int numTxn = ((transactions[offset++] & 0xFF) << 0) | + int numTxn = ((transactions[offset++] & 0xFF)) | ((transactions[offset++] & 0xFF) << 8) | ((transactions[offset++] & 0xFF) << 16) | ((transactions[offset++] & 0xFF) << 24); diff --git a/core/src/main/java/org/bitcoinj/store/PostgresFullPrunedBlockStore.java b/core/src/main/java/org/bitcoinj/store/PostgresFullPrunedBlockStore.java index e41cdc23..c2d48e1e 100644 --- a/core/src/main/java/org/bitcoinj/store/PostgresFullPrunedBlockStore.java +++ b/core/src/main/java/org/bitcoinj/store/PostgresFullPrunedBlockStore.java @@ -180,7 +180,7 @@ public class PostgresFullPrunedBlockStore extends DatabaseFullPrunedBlockStore { txOutChanges = bos.toByteArray(); } else { int numTxn = undoableBlock.getTransactions().size(); - bos.write((int) (0xFF & (numTxn >> 0))); + bos.write((int) (0xFF & numTxn)); bos.write((int) (0xFF & (numTxn >> 8))); bos.write((int) (0xFF & (numTxn >> 16))); bos.write((int) (0xFF & (numTxn >> 24))); diff --git a/core/src/test/java/org/bitcoinj/core/FullBlockTestGenerator.java b/core/src/test/java/org/bitcoinj/core/FullBlockTestGenerator.java index 71481c1a..c6c93dec 100644 --- a/core/src/test/java/org/bitcoinj/core/FullBlockTestGenerator.java +++ b/core/src/test/java/org/bitcoinj/core/FullBlockTestGenerator.java @@ -158,7 +158,7 @@ public class FullBlockTestGenerator { outStream.write((int) (params.getPacketMagic() >>> 24)); outStream.write((int) (params.getPacketMagic() >>> 16)); outStream.write((int) (params.getPacketMagic() >>> 8)); - outStream.write((int) (params.getPacketMagic() >>> 0)); + outStream.write((int) params.getPacketMagic()); byte[] block = ((BlockAndValidity)element).block.bitcoinSerialize(); byte[] length = new byte[4]; Utils.uint32ToByteArrayBE(block.length, length, 0);