Swap order of masks when assigning bytes to byte[] elements.

Masking a byte by 0xFF does nothing, and the optimizer can see that. I don't think these 0xFF masks do anything in java... but they're in a lot of places so if we remove them entirely it'll be in another CL.

Before (android):
```
ldr w3, [x1, #12]
and w4, w2, #0x7f
orr w4, w4, #0x80
add w5, w3, #0x1 (1)
sxtb w4, w4
```
after:
```
ldr w3, [x1, #12]
orr w4, w2, #0x80
add w5, w3, #0x1 (1)
sxtb w4, w4
```
PiperOrigin-RevId: 591117756
pull/15088/head
Protobuf Team Bot 1 year ago committed by Copybara-Service
parent 0a2f7757e3
commit 220415ddfb
  1. 26
      java/core/src/main/java/com/google/protobuf/CodedOutputStream.java

@ -1332,7 +1332,7 @@ public abstract class CodedOutputStream extends ByteOutput {
buffer[position++] = (byte) value;
return;
} else {
buffer[position++] = (byte) ((value & 0x7F) | 0x80);
buffer[position++] = (byte) ((value | 0x80) & 0xFF);
value >>>= 7;
}
}
@ -1363,7 +1363,7 @@ public abstract class CodedOutputStream extends ByteOutput {
UnsafeUtil.putByte(buffer, position++, (byte) value);
return;
} else {
UnsafeUtil.putByte(buffer, position++, (byte) (((int) value & 0x7F) | 0x80));
UnsafeUtil.putByte(buffer, position++, (byte) (((int) value | 0x80) & 0xFF));
value >>>= 7;
}
}
@ -1374,7 +1374,7 @@ public abstract class CodedOutputStream extends ByteOutput {
buffer[position++] = (byte) value;
return;
} else {
buffer[position++] = (byte) (((int) value & 0x7F) | 0x80);
buffer[position++] = (byte) (((int) value | 0x80) & 0xFF);
value >>>= 7;
}
}
@ -1690,7 +1690,7 @@ public abstract class CodedOutputStream extends ByteOutput {
buffer.put((byte) value);
return;
} else {
buffer.put((byte) ((value & 0x7F) | 0x80));
buffer.put((byte) ((value | 0x80) & 0xFF));
value >>>= 7;
}
}
@ -1716,7 +1716,7 @@ public abstract class CodedOutputStream extends ByteOutput {
buffer.put((byte) value);
return;
} else {
buffer.put((byte) (((int) value & 0x7F) | 0x80));
buffer.put((byte) (((int) value | 0x80) & 0xFF));
value >>>= 7;
}
}
@ -2021,7 +2021,7 @@ public abstract class CodedOutputStream extends ByteOutput {
UnsafeUtil.putByte(position++, (byte) value);
return;
} else {
UnsafeUtil.putByte(position++, (byte) ((value & 0x7F) | 0x80));
UnsafeUtil.putByte(position++, (byte) ((value | 0x80) & 0xFF));
value >>>= 7;
}
}
@ -2031,7 +2031,7 @@ public abstract class CodedOutputStream extends ByteOutput {
UnsafeUtil.putByte(position++, (byte) value);
return;
} else {
UnsafeUtil.putByte(position++, (byte) ((value & 0x7F) | 0x80));
UnsafeUtil.putByte(position++, (byte) ((value | 0x80) & 0xFF));
value >>>= 7;
}
}
@ -2055,7 +2055,7 @@ public abstract class CodedOutputStream extends ByteOutput {
UnsafeUtil.putByte(position++, (byte) value);
return;
} else {
UnsafeUtil.putByte(position++, (byte) (((int) value & 0x7F) | 0x80));
UnsafeUtil.putByte(position++, (byte) (((int) value | 0x80) & 0xFF));
value >>>= 7;
}
}
@ -2065,7 +2065,7 @@ public abstract class CodedOutputStream extends ByteOutput {
UnsafeUtil.putByte(position++, (byte) value);
return;
} else {
UnsafeUtil.putByte(position++, (byte) (((int) value & 0x7F) | 0x80));
UnsafeUtil.putByte(position++, (byte) (((int) value | 0x80) & 0xFF));
value >>>= 7;
}
}
@ -2265,7 +2265,7 @@ public abstract class CodedOutputStream extends ByteOutput {
UnsafeUtil.putByte(buffer, position++, (byte) value);
break;
} else {
UnsafeUtil.putByte(buffer, position++, (byte) ((value & 0x7F) | 0x80));
UnsafeUtil.putByte(buffer, position++, (byte) ((value | 0x80) & 0xFF));
value >>>= 7;
}
}
@ -2278,7 +2278,7 @@ public abstract class CodedOutputStream extends ByteOutput {
totalBytesWritten++;
return;
} else {
buffer[position++] = (byte) ((value & 0x7F) | 0x80);
buffer[position++] = (byte) ((value | 0x80) & 0xFF);
totalBytesWritten++;
value >>>= 7;
}
@ -2298,7 +2298,7 @@ public abstract class CodedOutputStream extends ByteOutput {
UnsafeUtil.putByte(buffer, position++, (byte) value);
break;
} else {
UnsafeUtil.putByte(buffer, position++, (byte) (((int) value & 0x7F) | 0x80));
UnsafeUtil.putByte(buffer, position++, (byte) (((int) value | 0x80) & 0xFF));
value >>>= 7;
}
}
@ -2311,7 +2311,7 @@ public abstract class CodedOutputStream extends ByteOutput {
totalBytesWritten++;
return;
} else {
buffer[position++] = (byte) (((int) value & 0x7F) | 0x80);
buffer[position++] = (byte) (((int) value | 0x80) & 0xFF);
totalBytesWritten++;
value >>>= 7;
}

Loading…
Cancel
Save