[libc-commits] [PATCH] D84875: [libc] Adds strrchr implementation.

Chris Gyurgyik via Phabricator via libc-commits libc-commits at lists.llvm.org
Fri Jul 31 11:33:24 PDT 2020


cgyurgyik marked an inline comment as done.
cgyurgyik added a comment.

Thanks for the review Siva.



================
Comment at: libc/src/string/strrchr.cpp:24
+      last_occurrence = str;
+  } while (*str++);
+  return reinterpret_cast<char *>(last_occurrence);
----------------
sivachandra wrote:
> Nit: To avoid the post-increment operator, may be:
> 
> ```
> for (; ; ++str) {
>   if (*str == ch)
>     last_occurance = str;
>   if (*str == '\0')
>     break;
> }
> ```
> 
> To me personally, mixing post/pre-increment operators with other operators make it hard to read so this comment is also driven by my personal preference.
I battled with this for a bit as well, but found using a `do...while` loop cleaner. For this reason, I'm going to leave it as is. 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D84875



More information about the libc-commits mailing list