[libc-commits] [PATCH] D91399: Add strncpy implementation.

Siva Chandra via Phabricator via libc-commits libc-commits at lists.llvm.org
Fri Nov 20 23:34:19 PST 2020


sivachandra added a subscriber: gchatelet.
sivachandra added a comment.

Thanks for your patience.



================
Comment at: libc/src/string/strncpy.cpp:19
+                                    const char *__restrict src, size_t n) {
+  for (size_t i = 0, j = 0; i < n; ++i) {
+    if (*(src + j) != '\0') {
----------------
cheng.w wrote:
> sivachandra wrote:
> > WDYT about a `memcpy` followed by a `memset` (for the null characters)? Both these functions in libcs are //optimized// in some manner so we will be leveraging that. We will need an additional `strlen` operation though.
> By referring to `strcpy`, I used `memcpy` and `strlen` at first. 
> But it seems that this method avoids the overhead of:
> - `strlen` goes through `src` for the length.
> - function calls.
> I am not sure whick method is more appropriate. So I upload it for suggestions.
> By referring to `strcpy`, I used `memcpy` and `strlen` at first. 
> But it seems that this method avoids the overhead of:
> - `strlen` goes through `src` for the length.
> - function calls.
> I am not sure whick method is more appropriate. So I upload it for suggestions.

I am not opposed to any approach. At the same time, I do not feel qualified enough to drive an opinion. So, adding @gchatelet for guidance.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D91399



More information about the libc-commits mailing list