提交 550c3ca1 authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

Simplify bitmasks in writeVarInt() and writeVarLong()

上级 23103d2b
......@@ -256,7 +256,7 @@ public final class DataUtils {
*/
public static void writeVarInt(OutputStream out, int x) throws IOException {
while ((x & ~0x7f) != 0) {
out.write((byte) (0x80 | (x & 0x7f)));
out.write((byte) (x | 0x80));
x >>>= 7;
}
out.write((byte) x);
......@@ -270,7 +270,7 @@ public final class DataUtils {
*/
public static void writeVarInt(ByteBuffer buff, int x) {
while ((x & ~0x7f) != 0) {
buff.put((byte) (0x80 | (x & 0x7f)));
buff.put((byte) (x | 0x80));
x >>>= 7;
}
buff.put((byte) x);
......@@ -331,7 +331,7 @@ public final class DataUtils {
*/
public static void writeVarLong(ByteBuffer buff, long x) {
while ((x & ~0x7f) != 0) {
buff.put((byte) (0x80 | (x & 0x7f)));
buff.put((byte) (x | 0x80));
x >>>= 7;
}
buff.put((byte) x);
......@@ -347,7 +347,7 @@ public final class DataUtils {
public static void writeVarLong(OutputStream out, long x)
throws IOException {
while ((x & ~0x7f) != 0) {
out.write((byte) (0x80 | (x & 0x7f)));
out.write((byte) (x | 0x80));
x >>>= 7;
}
out.write((byte) x);
......
......@@ -1224,7 +1224,7 @@ public class Data {
*/
public void writeVarInt(int x) {
while ((x & ~0x7f) != 0) {
data[pos++] = (byte) (0x80 | (x & 0x7f));
data[pos++] = (byte) (x | 0x80);
x >>>= 7;
}
data[pos++] = (byte) x;
......@@ -1293,7 +1293,7 @@ public class Data {
*/
public void writeVarLong(long x) {
while ((x & ~0x7f) != 0) {
data[pos++] = (byte) ((x & 0x7f) | 0x80);
data[pos++] = (byte) (x | 0x80);
x >>>= 7;
}
data[pos++] = (byte) x;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论