From 2163dcadb85b13f7da4478deba8f0bf277480061 Mon Sep 17 00:00:00 2001 From: Sriya Pratipati Date: Tue, 17 Jun 2025 17:11:49 +0000 Subject: [PATCH 1/3] [libc] Moved shared constexpr to the top Some conversions shared constexpr so moved to the top. --- libc/src/__support/wchar/character_converter.cpp | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/libc/src/__support/wchar/character_converter.cpp b/libc/src/__support/wchar/character_converter.cpp index 3b9046dfb9a76..e45ee4105c285 100644 --- a/libc/src/__support/wchar/character_converter.cpp +++ b/libc/src/__support/wchar/character_converter.cpp @@ -19,6 +19,12 @@ namespace LIBC_NAMESPACE_DECL { namespace internal { +constexpr size_t ENCODED_BITS_PER_UTF8 = 6; +// the number of bits per utf-8 byte that actually encode character +// information not metadata (# of bits excluding the byte headers) +constexpr uint32_t MASK_ENCODED_BITS = + mask_trailing_ones(); + CharacterConverter::CharacterConverter(mbstate *mbstate) { state = mbstate; } void CharacterConverter::clear() { @@ -61,10 +67,9 @@ int CharacterConverter::push(char8_t utf8_byte) { } // Any subsequent push // Adding 6 more bits so need to left shift - constexpr size_t ENCODED_BITS_PER_UTF8 = 6; if (num_ones == 1 && !isComplete()) { char32_t byte = - utf8_byte & mask_trailing_ones(); + utf8_byte & MASK_ENCODED_BITS; state->partial = state->partial << ENCODED_BITS_PER_UTF8; state->partial |= byte; state->bytes_processed++; @@ -117,12 +122,6 @@ ErrorOr CharacterConverter::pop_utf8() { constexpr char8_t FIRST_BYTE_HEADERS[] = {0, 0xC0, 0xE0, 0xF0}; constexpr char8_t CONTINUING_BYTE_HEADER = 0x80; - // the number of bits per utf-8 byte that actually encode character - // information not metadata (# of bits excluding the byte headers) - constexpr size_t ENCODED_BITS_PER_UTF8 = 6; - constexpr int MASK_ENCODED_BITS = - mask_trailing_ones(); - char32_t output; // Shift to get the next 6 bits from the utf32 encoding From e576531e3ac33b720e933b637579346ab96f292d Mon Sep 17 00:00:00 2001 From: Sriya Pratipati Date: Tue, 17 Jun 2025 17:17:21 +0000 Subject: [PATCH 2/3] fixed formatting --- libc/src/__support/wchar/character_converter.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/libc/src/__support/wchar/character_converter.cpp b/libc/src/__support/wchar/character_converter.cpp index e45ee4105c285..ecc0ba30633ff 100644 --- a/libc/src/__support/wchar/character_converter.cpp +++ b/libc/src/__support/wchar/character_converter.cpp @@ -68,8 +68,7 @@ int CharacterConverter::push(char8_t utf8_byte) { // Any subsequent push // Adding 6 more bits so need to left shift if (num_ones == 1 && !isComplete()) { - char32_t byte = - utf8_byte & MASK_ENCODED_BITS; + char32_t byte = utf8_byte & MASK_ENCODED_BITS; state->partial = state->partial << ENCODED_BITS_PER_UTF8; state->partial |= byte; state->bytes_processed++; From 6afa7711d0d87b67fde8aab6130aee3e14ec6283 Mon Sep 17 00:00:00 2001 From: Sriya Pratipati Date: Tue, 17 Jun 2025 17:24:23 +0000 Subject: [PATCH 3/3] added comment --- libc/src/__support/wchar/character_converter.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/libc/src/__support/wchar/character_converter.cpp b/libc/src/__support/wchar/character_converter.cpp index ecc0ba30633ff..5ab0447bb08b2 100644 --- a/libc/src/__support/wchar/character_converter.cpp +++ b/libc/src/__support/wchar/character_converter.cpp @@ -19,9 +19,10 @@ namespace LIBC_NAMESPACE_DECL { namespace internal { +// This is for utf-8 bytes other than the first byte constexpr size_t ENCODED_BITS_PER_UTF8 = 6; -// the number of bits per utf-8 byte that actually encode character -// information not metadata (# of bits excluding the byte headers) +// The number of bits per utf-8 byte that actually encode character +// Information not metadata (# of bits excluding the byte headers) constexpr uint32_t MASK_ENCODED_BITS = mask_trailing_ones();