[libc-commits] [PATCH] D106511: [libc][NFC] Optimize and standardize the C string functions

Alf via Phabricator via libc-commits libc-commits at lists.llvm.org
Wed Jul 28 12:42:10 PDT 2021


gAlfonso-bit added a comment.

Done!



================
Comment at: libc/src/string/memrchr.cpp:19
   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);
----------------
sivachandra wrote:
> Instead of folding existing code into patterns like this (using an increment and decrement operator along with a another operator like the dereference operator), I would suggest doing the other way round cleanup. For example, the existing code is more readable than this new code.
The code is more efficient this way than the last way.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D106511/new/

https://reviews.llvm.org/D106511



More information about the libc-commits mailing list