Skip to content

Commit a5e8646

Browse files
committed
removed redundant bool
1 parent 8e969d9 commit a5e8646

File tree

2 files changed

+5
-13
lines changed

2 files changed

+5
-13
lines changed

libc/src/__support/wchar/string_converter.h

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,6 @@ template <typename T> class StringConverter {
3030
// # of pops we are allowed to perform (essentially size of the dest buffer)
3131
size_t num_to_write;
3232

33-
// on the very first pop, we need to make sure that we always
34-
// pushFullCharacter in case a previous StringConverter pushed part of a
35-
// character to the mbstate
36-
bool first_pop;
37-
3833
ErrorOr<size_t> pushFullCharacter() {
3934
size_t num_pushed;
4035
for (num_pushed = 0; !cr.isFull() && src_idx + num_pushed < src_len;
@@ -56,14 +51,12 @@ template <typename T> class StringConverter {
5651
public:
5752
StringConverter(const T *s, mbstate *ps, size_t dstlen,
5853
size_t srclen = SIZE_MAX)
59-
: cr(ps), src(s), src_len(srclen), src_idx(0), num_to_write(dstlen),
60-
first_pop(true) {}
54+
: cr(ps), src(s), src_len(srclen), src_idx(0), num_to_write(dstlen) {}
6155

6256
// TODO: following functions are almost identical
6357
// look into templating CharacterConverter pop functions
6458
ErrorOr<char32_t> popUTF32() {
65-
if (cr.isEmpty() || first_pop) {
66-
first_pop = false;
59+
if (cr.isEmpty() || src_idx == 0) {
6760
auto src_elements_read = pushFullCharacter();
6861
if (!src_elements_read.has_value())
6962
return Error(src_elements_read.error());
@@ -86,8 +79,7 @@ template <typename T> class StringConverter {
8679
}
8780

8881
ErrorOr<char8_t> popUTF8() {
89-
if (cr.isEmpty() || first_pop) {
90-
first_pop = false;
82+
if (cr.isEmpty() || src_idx == 0) {
9183
auto src_elements_read = pushFullCharacter();
9284
if (!src_elements_read.has_value())
9385
return Error(src_elements_read.error());

libc/test/src/__support/wchar/string_converter_test.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ TEST(LlvmLibcStringConverterTest, DestLimitUTF8To32) {
306306
const char *src = "\xF0\x9F\xA4\xA1\xF0\x9F\xA4\xA1"; // 2 clown emojis
307307
LIBC_NAMESPACE::internal::mbstate state;
308308
LIBC_NAMESPACE::internal::StringConverter<char8_t> sc(
309-
reinterpret_cast<const char8_t *>(src), &state, 1, SIZE_MAX);
309+
reinterpret_cast<const char8_t *>(src), &state, 1);
310310

311311
auto res = sc.popUTF32();
312312
ASSERT_TRUE(res.has_value());
@@ -320,7 +320,7 @@ TEST(LlvmLibcStringConverterTest, DestLimitUTF32To8) {
320320
const wchar_t *src = L"\x1f921\x1f921"; // 2 clown emojis
321321
LIBC_NAMESPACE::internal::mbstate state;
322322
LIBC_NAMESPACE::internal::StringConverter<char32_t> sc(
323-
reinterpret_cast<const char32_t *>(src), &state, 5, SIZE_MAX);
323+
reinterpret_cast<const char32_t *>(src), &state, 5);
324324

325325
auto res = sc.popUTF8();
326326
ASSERT_TRUE(res.has_value());

0 commit comments

Comments
 (0)