Skip to content

Commit ff1b3b0

Browse files
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: 590766320
1 parent 543fbcd commit ff1b3b0

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

java/core/src/main/java/com/google/protobuf/CodedOutputStream.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1326,7 +1326,7 @@ public final void writeUInt32NoTag(int value) throws IOException {
13261326
buffer[position++] = (byte) value;
13271327
return;
13281328
} else {
1329-
buffer[position++] = (byte) ((value & 0x7F) | 0x80);
1329+
buffer[position++] = (byte) ((value | 0x80) & 0xFF);
13301330
value >>>= 7;
13311331
}
13321332
}
@@ -1357,7 +1357,7 @@ public final void writeUInt64NoTag(long value) throws IOException {
13571357
UnsafeUtil.putByte(buffer, position++, (byte) value);
13581358
return;
13591359
} else {
1360-
UnsafeUtil.putByte(buffer, position++, (byte) (((int) value & 0x7F) | 0x80));
1360+
UnsafeUtil.putByte(buffer, position++, (byte) (((int) value | 0x80) & 0xFF));
13611361
value >>>= 7;
13621362
}
13631363
}
@@ -1368,7 +1368,7 @@ public final void writeUInt64NoTag(long value) throws IOException {
13681368
buffer[position++] = (byte) value;
13691369
return;
13701370
} else {
1371-
buffer[position++] = (byte) (((int) value & 0x7F) | 0x80);
1371+
buffer[position++] = (byte) (((int) value | 0x80) & 0xFF);
13721372
value >>>= 7;
13731373
}
13741374
}
@@ -1684,7 +1684,7 @@ public void writeUInt32NoTag(int value) throws IOException {
16841684
buffer.put((byte) value);
16851685
return;
16861686
} else {
1687-
buffer.put((byte) ((value & 0x7F) | 0x80));
1687+
buffer.put((byte) ((value | 0x80) & 0xFF));
16881688
value >>>= 7;
16891689
}
16901690
}
@@ -1710,7 +1710,7 @@ public void writeUInt64NoTag(long value) throws IOException {
17101710
buffer.put((byte) value);
17111711
return;
17121712
} else {
1713-
buffer.put((byte) (((int) value & 0x7F) | 0x80));
1713+
buffer.put((byte) (((int) value | 0x80) & 0xFF));
17141714
value >>>= 7;
17151715
}
17161716
}
@@ -2015,7 +2015,7 @@ public void writeUInt32NoTag(int value) throws IOException {
20152015
UnsafeUtil.putByte(position++, (byte) value);
20162016
return;
20172017
} else {
2018-
UnsafeUtil.putByte(position++, (byte) ((value & 0x7F) | 0x80));
2018+
UnsafeUtil.putByte(position++, (byte) ((value | 0x80) & 0xFF));
20192019
value >>>= 7;
20202020
}
20212021
}
@@ -2025,7 +2025,7 @@ public void writeUInt32NoTag(int value) throws IOException {
20252025
UnsafeUtil.putByte(position++, (byte) value);
20262026
return;
20272027
} else {
2028-
UnsafeUtil.putByte(position++, (byte) ((value & 0x7F) | 0x80));
2028+
UnsafeUtil.putByte(position++, (byte) ((value | 0x80) & 0xFF));
20292029
value >>>= 7;
20302030
}
20312031
}
@@ -2049,7 +2049,7 @@ public void writeUInt64NoTag(long value) throws IOException {
20492049
UnsafeUtil.putByte(position++, (byte) value);
20502050
return;
20512051
} else {
2052-
UnsafeUtil.putByte(position++, (byte) (((int) value & 0x7F) | 0x80));
2052+
UnsafeUtil.putByte(position++, (byte) (((int) value | 0x80) & 0xFF));
20532053
value >>>= 7;
20542054
}
20552055
}
@@ -2059,7 +2059,7 @@ public void writeUInt64NoTag(long value) throws IOException {
20592059
UnsafeUtil.putByte(position++, (byte) value);
20602060
return;
20612061
} else {
2062-
UnsafeUtil.putByte(position++, (byte) (((int) value & 0x7F) | 0x80));
2062+
UnsafeUtil.putByte(position++, (byte) (((int) value| 0x80) & 0xFF));
20632063
value >>>= 7;
20642064
}
20652065
}
@@ -2259,7 +2259,7 @@ final void bufferUInt32NoTag(int value) {
22592259
UnsafeUtil.putByte(buffer, position++, (byte) value);
22602260
break;
22612261
} else {
2262-
UnsafeUtil.putByte(buffer, position++, (byte) ((value & 0x7F) | 0x80));
2262+
UnsafeUtil.putByte(buffer, position++, (byte) ((value | 0x80) & 0xFF));
22632263
value >>>= 7;
22642264
}
22652265
}
@@ -2272,7 +2272,7 @@ final void bufferUInt32NoTag(int value) {
22722272
totalBytesWritten++;
22732273
return;
22742274
} else {
2275-
buffer[position++] = (byte) ((value & 0x7F) | 0x80);
2275+
buffer[position++] = (byte) ((value | 0x80) & 0xFF);
22762276
totalBytesWritten++;
22772277
value >>>= 7;
22782278
}
@@ -2292,7 +2292,7 @@ final void bufferUInt64NoTag(long value) {
22922292
UnsafeUtil.putByte(buffer, position++, (byte) value);
22932293
break;
22942294
} else {
2295-
UnsafeUtil.putByte(buffer, position++, (byte) (((int) value & 0x7F) | 0x80));
2295+
UnsafeUtil.putByte(buffer, position++, (byte) (((int) value | 0x80) & 0xFF));
22962296
value >>>= 7;
22972297
}
22982298
}
@@ -2305,7 +2305,7 @@ final void bufferUInt64NoTag(long value) {
23052305
totalBytesWritten++;
23062306
return;
23072307
} else {
2308-
buffer[position++] = (byte) (((int) value & 0x7F) | 0x80);
2308+
buffer[position++] = (byte) (((int) value | 0x80) & 0xFF);
23092309
totalBytesWritten++;
23102310
value >>>= 7;
23112311
}

0 commit comments

Comments
 (0)