Skip to content

Commit

Permalink
Patch 9 (#4)
Browse files Browse the repository at this point in the history
* Update strchr.cpp

* Add explicit cast (#3)

We need to have the most efficient c++ casting
  • Loading branch information
AZero13 authored Jul 22, 2021
1 parent 1c7c8da commit b979477
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
12 changes: 6 additions & 6 deletions libc/src/string/strchr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ namespace __llvm_libc {

// TODO: Look at performance benefits of comparing words.
LLVM_LIBC_FUNCTION(char *, strchr, (const char *src, int c)) {
unsigned char *str =
const_cast<unsigned char *>(reinterpret_cast<const unsigned char *>(src));
const unsigned char ch = c;
for (; *str && *str != ch; ++str)
;
return *str == ch ? reinterpret_cast<char *>(str) : nullptr;
const char ch = static_cast<char>(c);
for (; *src != ch; ++src)
if (!*src)
return nullptr;

return const_cast<char *>(src);
}

} // namespace __llvm_libc
2 changes: 1 addition & 1 deletion libc/src/string/strrchr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
namespace __llvm_libc {

LLVM_LIBC_FUNCTION(char *, strrchr, (const char *src, int c)) {
const char ch = c;
const char ch = static_cast<char>(c);
char *last_occurrence = nullptr;
do {
if (*src == ch)
Expand Down

0 comments on commit b979477

Please sign in to comment.