Skip to content

Commit 2163dca

Browse files
author
Sriya Pratipati
committed
[libc] Moved shared constexpr to the top
Some conversions shared constexpr so moved to the top.
1 parent 556e69b commit 2163dca

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

libc/src/__support/wchar/character_converter.cpp

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

22+
constexpr size_t ENCODED_BITS_PER_UTF8 = 6;
23+
// the number of bits per utf-8 byte that actually encode character
24+
// information not metadata (# of bits excluding the byte headers)
25+
constexpr uint32_t MASK_ENCODED_BITS =
26+
mask_trailing_ones<uint32_t, ENCODED_BITS_PER_UTF8>();
27+
2228
CharacterConverter::CharacterConverter(mbstate *mbstate) { state = mbstate; }
2329

2430
void CharacterConverter::clear() {
@@ -61,10 +67,9 @@ int CharacterConverter::push(char8_t utf8_byte) {
6167
}
6268
// Any subsequent push
6369
// Adding 6 more bits so need to left shift
64-
constexpr size_t ENCODED_BITS_PER_UTF8 = 6;
6570
if (num_ones == 1 && !isComplete()) {
6671
char32_t byte =
67-
utf8_byte & mask_trailing_ones<uint32_t, ENCODED_BITS_PER_UTF8>();
72+
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)