Skip to content

Commit 844e41c

Browse files
sribee8Sriya Pratipati
andauthored
[libc] Moved shared constexpr to the top (#144569)
Some conversions shared constexpr so moved to the top. --------- Co-authored-by: Sriya Pratipati <sriyap@google.com>
1 parent a5a0d88 commit 844e41c

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

libc/src/__support/wchar/character_converter.cpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@
1919
namespace LIBC_NAMESPACE_DECL {
2020
namespace internal {
2121

22+
// This is for utf-8 bytes other than the first byte
23+
constexpr size_t ENCODED_BITS_PER_UTF8 = 6;
24+
// The number of bits per utf-8 byte that actually encode character
25+
// Information not metadata (# of bits excluding the byte headers)
26+
constexpr uint32_t MASK_ENCODED_BITS =
27+
mask_trailing_ones<uint32_t, ENCODED_BITS_PER_UTF8>();
28+
2229
CharacterConverter::CharacterConverter(mbstate *mbstate) { state = mbstate; }
2330

2431
void CharacterConverter::clear() {
@@ -61,10 +68,8 @@ int CharacterConverter::push(char8_t utf8_byte) {
6168
}
6269
// Any subsequent push
6370
// Adding 6 more bits so need to left shift
64-
constexpr size_t ENCODED_BITS_PER_UTF8 = 6;
6571
if (num_ones == 1 && !isComplete()) {
66-
char32_t byte =
67-
utf8_byte & mask_trailing_ones<uint32_t, ENCODED_BITS_PER_UTF8>();
72+
char32_t byte = utf8_byte & MASK_ENCODED_BITS;
6873
state->partial = state->partial << ENCODED_BITS_PER_UTF8;
6974
state->partial |= byte;
7075
state->bytes_processed++;
@@ -117,12 +122,6 @@ ErrorOr<char8_t> CharacterConverter::pop_utf8() {
117122
constexpr char8_t FIRST_BYTE_HEADERS[] = {0, 0xC0, 0xE0, 0xF0};
118123
constexpr char8_t CONTINUING_BYTE_HEADER = 0x80;
119124

120-
// the number of bits per utf-8 byte that actually encode character
121-
// information not metadata (# of bits excluding the byte headers)
122-
constexpr size_t ENCODED_BITS_PER_UTF8 = 6;
123-
constexpr int MASK_ENCODED_BITS =
124-
mask_trailing_ones<unsigned int, ENCODED_BITS_PER_UTF8>();
125-
126125
char32_t output;
127126

128127
// Shift to get the next 6 bits from the utf32 encoding

0 commit comments

Comments
 (0)