[libc-commits] [PATCH] D106511: [libc] Add explicit C++ casting to strrchr
Alf via Phabricator via libc-commits
libc-commits at lists.llvm.org
Wed Jul 21 17:36:56 PDT 2021
gAlfonso-bit updated this revision to Diff 360662.
gAlfonso-bit added a comment.
Did the same to strchr while also simplifying it
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D106511/new/
https://reviews.llvm.org/D106511
Files:
libc/src/string/strchr.cpp
libc/src/string/strrchr.cpp
Index: libc/src/string/strrchr.cpp
===================================================================
--- libc/src/string/strrchr.cpp
+++ libc/src/string/strrchr.cpp
@@ -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)
Index: libc/src/string/strchr.cpp
===================================================================
--- libc/src/string/strchr.cpp
+++ libc/src/string/strchr.cpp
@@ -14,12 +14,12 @@
// 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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D106511.360662.patch
Type: text/x-patch
Size: 1138 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libc-commits/attachments/20210722/1d6651f3/attachment.bin>
More information about the libc-commits
mailing list