Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Patch 10 #6

Merged
merged 3 commits into from
Jul 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions libc/src/string/memrchr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,10 @@ namespace __llvm_libc {

LLVM_LIBC_FUNCTION(void *, memrchr, (const void *src, int c, size_t n)) {
const unsigned char *str = reinterpret_cast<const unsigned char *>(src);
const unsigned char ch = c;
const unsigned char ch = static_cast<unsigned char>(c);
for (; n != 0; --n) {
const unsigned char *s = str + n - 1;
if (*s == ch)
return const_cast<unsigned char *>(s);
if (*(--str) == ch)
return const_cast<unsigned char *>(str);
}
return nullptr;
}
Expand Down
18 changes: 9 additions & 9 deletions libc/src/string/string_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,26 @@ namespace internal {
// Returns the length of a string, denoted by the first occurrence
// of a null terminator.
static inline size_t string_length(const char *src) {
size_t length;
for (length = 0; *src; ++src, ++length)
const char * const initial = src;
for (; *src; ++src)
;
return length;
return src - initial;
}

// Returns the first occurrence of 'ch' within the first 'n' characters of
// 'src'. If 'ch' is not found, returns nullptr.
static inline void *find_first_character(const unsigned char *src,
unsigned char ch, size_t n) {
for (; n && *src != ch; --n, ++src)
;
return n ? const_cast<unsigned char *>(src) : nullptr;
for (; n; --n, ++src)
if (*src == ch)
return const_cast<unsigned char *>(src);
return nullptr;
}

// Returns the maximum length span that contains only characters not found in
// 'segment'. If no characters are found, returns the length of 'src'.
static inline size_t complementary_span(const char *src, const char *segment) {
const char *initial = src;
const char * const initial = src;
cpp::Bitset<256> bitset;

for (; *segment; ++segment)
Expand Down Expand Up @@ -73,8 +74,7 @@ static inline char *string_token(char *__restrict src,
for (; *src && !delimiter_set.test(*src); ++src)
;
if (*src) {
*src = '\0';
++src;
*src++ = '\0';
}
*saveptr = src;
return token;
Expand Down