Simplify Bitwise operations (#11547)

Motivation:
We should keep bitwise operations simple and easy to understand.

Modification:
Simplify few Bitwise operations.

Result:
Less complicated bitwise operation code
This commit is contained in:
Aayush Atharva 2021-08-06 12:46:32 +05:30 committed by GitHub
parent 45c97fbdfd
commit a3c4c9ebfd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 3 additions and 3 deletions

View File

@ -38,7 +38,7 @@ public abstract class AbstractDnsOptPseudoRrRecord extends AbstractDnsRecord imp
// See https://tools.ietf.org/html/rfc6891#section-6.1.3 // See https://tools.ietf.org/html/rfc6891#section-6.1.3
private static long packIntoLong(int val, int val2) { private static long packIntoLong(int val, int val2) {
// We are currently not support DO and Z fields, just use 0. // We are currently not support DO and Z fields, just use 0.
return ((val & 0xff) << 24 | (val2 & 0xff) << 16 | (0 & 0xff) << 8 | 0 & 0xff) & 0xFFFFFFFFL; return ((val & 0xffL) << 24 | (val2 & 0xff) << 16) & 0xFFFFFFFFL;
} }
@Override @Override

View File

@ -97,7 +97,7 @@ public class DefaultDnsRecordEncoderTest {
// Pad the leftover of the last byte with zeros. // Pad the leftover of the last byte with zeros.
int idx = addressPart.writerIndex() - 1; int idx = addressPart.writerIndex() - 1;
byte lastByte = addressPart.getByte(idx); byte lastByte = addressPart.getByte(idx);
int paddingMask = ~((1 << (8 - lowOrderBitsToPreserve)) - 1); int paddingMask = -1 << 8 - lowOrderBitsToPreserve;
addressPart.setByte(idx, lastByte & paddingMask); addressPart.setByte(idx, lastByte & paddingMask);
} }

View File

@ -167,7 +167,7 @@ public final class IpSubnetFilterRule implements IpFilterRule, Comparable<IpSubn
* *
* Also see https://github.com/netty/netty/issues/2767 * Also see https://github.com/netty/netty/issues/2767
*/ */
return (int) ((-1L << 32 - cidrPrefix) & 0xffffffff); return (int) (-1L << 32 - cidrPrefix);
} }
} }