Skip to content

Commit f961982

Browse files
kazutakahirataDebadri Basak
authored andcommitted
[Support] Simplify the continuation condition in encodeSLEB128 (NFC) (llvm#165651)
The boolean expression to determine if more bytes are needed for a signed LEB128 value is quite complex: !((((Value == 0 ) && ((Byte & 0x40) == 0)) || ((Value == -1) && ((Byte & 0x40) != 0)))) This patch simplifies it to an equivalent expression using a ternary operator, which is much easier to understand.
1 parent d698df9 commit f961982

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

llvm/include/llvm/Support/LEB128.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ inline unsigned encodeSLEB128(int64_t Value, raw_ostream &OS,
2929
uint8_t Byte = Value & 0x7f;
3030
// NOTE: this assumes that this signed shift is an arithmetic right shift.
3131
Value >>= 7;
32-
More = !((((Value == 0 ) && ((Byte & 0x40) == 0)) ||
33-
((Value == -1) && ((Byte & 0x40) != 0))));
32+
More = Value != ((Byte & 0x40) ? -1 : 0);
3433
Count++;
3534
if (More || Count < PadTo)
3635
Byte |= 0x80; // Mark this byte to show that more bytes will follow.
@@ -58,8 +57,7 @@ inline unsigned encodeSLEB128(int64_t Value, uint8_t *p, unsigned PadTo = 0) {
5857
uint8_t Byte = Value & 0x7f;
5958
// NOTE: this assumes that this signed shift is an arithmetic right shift.
6059
Value >>= 7;
61-
More = !((((Value == 0 ) && ((Byte & 0x40) == 0)) ||
62-
((Value == -1) && ((Byte & 0x40) != 0))));
60+
More = Value != ((Byte & 0x40) ? -1 : 0);
6361
Count++;
6462
if (More || Count < PadTo)
6563
Byte |= 0x80; // Mark this byte to show that more bytes will follow.

0 commit comments

Comments
 (0)