Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: [PATCH v2] string.c: remove use of strcat() after strlen()



Since we are already calling strlen() beforehand to know the size of allocation, we can just memcpy() from BASE + BASE_LEN and avoid another strlen() call in strcat(). We should prefer memcpy() because we always know the length and most libc implementations provide an assembly implementation of memcpy but maybe not strcpy(). Even if it is implemented in assembly, memcpy() is likely to be faster than strcpy() since as the loop condition strcpy() needs to check for zeros in SRC, whereas memcpy() can just decrement the size.

I'm using a MEMPCPY macro because I don't know how zsh handles using GNU/POSIX extensions.

On Sun, Dec 31, 2023 at 11:22 AM Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
I take it this is intended to be an optimization?

Please do provide some background / rationale when sending a patch.  Thanks.


Messages sorted by: Reverse Date, Date, Thread, Author