Skip to content

Commit 9eca414

Browse files
committed
refactor(container): discourage using size_t with padded_string
1 parent 3ab471d commit 9eca414

File tree

4 files changed

+11
-13
lines changed

4 files changed

+11
-13
lines changed

src/quick-lint-js/container/padded-string.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,6 @@ class padded_string {
5151
return this->data_[narrow_cast<unsigned>(index)];
5252
}
5353

54-
const char8 &operator[](std::size_t index) const noexcept {
55-
QLJS_ASSERT(index <= narrow_cast<std::size_t>(this->size()));
56-
return this->data_[index];
57-
}
58-
5954
void resize(size_type new_size);
6055
void resize_grow_uninitialized(size_type new_size);
6156

src/quick-lint-js/port/char8.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ std::size_t strlen(const char8 *s) {
4242
return std::strlen(reinterpret_cast<const char *>(s));
4343
}
4444

45+
int strlen_i(const char8 *s) { return narrow_cast<int>(strlen(s)); }
46+
4547
const char8 *strchr(const char8 *haystack, char8 needle) {
4648
return reinterpret_cast<const char8 *>(std::strchr(
4749
reinterpret_cast<const char *>(haystack), static_cast<char>(needle)));

src/quick-lint-js/port/char8.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ std::string_view to_string_view(string8_view);
4747
string8_view to_string8_view(std::string_view);
4848

4949
std::size_t strlen(const char8 *);
50+
int strlen_i(const char8 *);
5051
const char8 *strchr(const char8 *haystack, char8 needle);
5152
const char8 *strstr(const char8 *haystack, const char8 *needle);
5253
std::size_t strspn(const char8 *haystack, const char8 *needles);

test/test-lex.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3342,8 +3342,8 @@ TEST_F(test_lex, jsx_string_ignores_comments) {
33423342
l.skip_in_jsx(); // Ignore '!'.
33433343

33443344
EXPECT_EQ(l.peek().type, token_type::string);
3345-
EXPECT_EQ(l.peek().begin, &code[strlen(u8"! ")]);
3346-
EXPECT_EQ(l.peek().end, &code[strlen(u8"! 'hello // '")])
3345+
EXPECT_EQ(l.peek().begin, &code[strlen_i(u8"! ")]);
3346+
EXPECT_EQ(l.peek().end, &code[strlen_i(u8"! 'hello // '")])
33473347
<< "string should end at ', treating // as part of the string";
33483348

33493349
l.skip_in_jsx();
@@ -3360,8 +3360,8 @@ TEST_F(test_lex, jsx_string_ignores_comments) {
33603360
l.skip_in_jsx(); // Ignore '!'.
33613361

33623362
EXPECT_EQ(l.peek().type, token_type::string);
3363-
EXPECT_EQ(l.peek().begin, &code[strlen(u8"! ")]);
3364-
EXPECT_EQ(l.peek().end, &code[strlen(u8R"(! "hello/* not")")])
3363+
EXPECT_EQ(l.peek().begin, &code[strlen_i(u8"! ")]);
3364+
EXPECT_EQ(l.peek().end, &code[strlen_i(u8R"(! "hello/* not")")])
33653365
<< "string should end at \", treating /* as part of the string";
33663366

33673367
l.skip_in_jsx();
@@ -3453,8 +3453,8 @@ TEST_F(test_lex, jsx_text_children) {
34533453
l.skip_in_jsx_children(); // Skip '>'.
34543454

34553455
EXPECT_EQ(l.peek().type, token_type::less);
3456-
EXPECT_EQ(l.peek().begin, &code[strlen(u8"<>hello")]);
3457-
EXPECT_EQ(l.peek().end, &code[strlen(u8"<>hello<")]);
3456+
EXPECT_EQ(l.peek().begin, &code[strlen_i(u8"<>hello")]);
3457+
EXPECT_EQ(l.peek().end, &code[strlen_i(u8"<>hello<")]);
34583458
EXPECT_THAT(errors.errors, IsEmpty());
34593459
}
34603460

@@ -3467,8 +3467,8 @@ TEST_F(test_lex, jsx_text_children) {
34673467
l.skip_in_jsx(); // Ignore '<'.
34683468

34693469
EXPECT_EQ(l.peek().type, token_type::greater);
3470-
EXPECT_EQ(l.peek().begin, &code[strlen(u8"<")]);
3471-
EXPECT_EQ(l.peek().end, &code[strlen(u8"<>")]);
3470+
EXPECT_EQ(l.peek().begin, &code[strlen_i(u8"<")]);
3471+
EXPECT_EQ(l.peek().end, &code[strlen_i(u8"<>")]);
34723472
l.skip_in_jsx_children();
34733473

34743474
EXPECT_EQ(l.peek().type, token_type::end_of_file);

0 commit comments

Comments
 (0)