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
diff --git a/java/core/src/main/java/com/google/protobuf/CodedOutputStream.java b/java/core/src/main/java/com/google/protobuf/CodedOutputStream.java
index cd8127b..2c28536 100644
--- a/java/core/src/main/java/com/google/protobuf/CodedOutputStream.java
+++ b/java/core/src/main/java/com/google/protobuf/CodedOutputStream.java
@@ -1332,7 +1332,7 @@
buffer[position++] = (byte) value;
return;
} else {
- buffer[position++] = (byte) ((value & 0x7F) | 0x80);
+ buffer[position++] = (byte) ((value | 0x80) & 0xFF);
value >>>= 7;
}
}
@@ -1363,7 +1363,7 @@
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 @@
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 @@
buffer.put((byte) value);
return;
} else {
- buffer.put((byte) ((value & 0x7F) | 0x80));
+ buffer.put((byte) ((value | 0x80) & 0xFF));
value >>>= 7;
}
}
@@ -1716,7 +1716,7 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
totalBytesWritten++;
return;
} else {
- buffer[position++] = (byte) ((value & 0x7F) | 0x80);
+ buffer[position++] = (byte) ((value | 0x80) & 0xFF);
totalBytesWritten++;
value >>>= 7;
}
@@ -2298,7 +2298,7 @@
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 @@
totalBytesWritten++;
return;
} else {
- buffer[position++] = (byte) (((int) value & 0x7F) | 0x80);
+ buffer[position++] = (byte) (((int) value | 0x80) & 0xFF);
totalBytesWritten++;
value >>>= 7;
}