yangguangcai01 commented on code in PR #13180: URL: https://github.com/apache/nuttx/pull/13180#discussion_r1806572740
########## libs/libc/string/lib_memccpy.c: ########## @@ -51,6 +81,71 @@ #undef memccpy /* See mm/README.txt */ FAR void *memccpy(FAR void *s1, FAR const void *s2, int c, size_t n) { +#ifdef CONFIG_LIBC_STRING_OPTIMIZE + FAR void *ptr = NULL; + FAR unsigned char *pout = (FAR unsigned char *)s1; + FAR const unsigned char *pin = (FAR const unsigned char *)s2; + FAR long *paligned_out; + FAR const long *paligned_in; + unsigned char endchar = c & 0xff; + + /* If the size is small, or either pin or pout is unaligned, + * then punt into the byte copy loop. This should be rare. + */ + + if (!TOO_SMALL(n) && !UNALIGNED(pin, pout)) + { + unsigned int i; + unsigned long mask = 0; + + paligned_out = (FAR long *)pout; + paligned_in = (FAR long *)pin; + + /* The fast code reads the ASCII one word at a time and only + * performs the bytewise search on word-sized segments if they + * contain the search character, which is detected by XORing + * the word-sized segment with a word-sized block of the search + * character and then detecting for the presence of NULL in the + * result. + */ + + for (i = 0; i < LITTLEBLOCKSIZE; i++) + { + mask = (mask << 8) + endchar; + } + + /* Copy one long word at a time if possible. */ + + while (n >= LITTLEBLOCKSIZE) + { + unsigned long buffer = (unsigned long)(*paligned_in); + buffer ^= mask; + if (DETECTNULL(buffer)) + { + break; /* endchar is found, go byte by byte from here */ + } + + *paligned_out++ = *paligned_in++; + n -= LITTLEBLOCKSIZE; + } + + /* Pick up any residual with a byte copier. */ + + pout = (FAR unsigned char *)paligned_out; + pin = (FAR unsigned char *)paligned_in; + } + + while (n--) + { + if ((*pout++ = *pin++) == endchar) + { + ptr = pout; + break; + } + } + + return ptr; +#else Review Comment: > i feel we should separate code with different license to separate files. how do you think? ok, I will separate these files. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@nuttx.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org