4 ms·
https://sourceware.org/git/?p=glibc.git;a=blob;f=string/strcpy.c;h=a4cce892df1fa6821128efaf203865f862027587;hb=refs/heads/release/2.28/master https://sourceware
by Someone 8y ago
https://sourceware.org/git/?p=glibc.git;a=blob;f=string/strcpy.c;h=a4cce892df1fa6821128efaf203865f862027587;hb=refs/heads/release/2.28/master https://sourceware.org/git/?p=glibc.git;a=blob;f=string/strc...:
return memcpy (dest, src, strlen (src) + 1);
I think the logic is that strlen is virtually free for short strings, and that memcpy can be a lot faster for long ones (reading https://sourceware.org/git/?p=glibc.git;a=blob;f=string/memcpy.c;h=ecfa2218472d1c6d136ba6849620a813349fa65b;hb=refs/heads/release/2.28/master https://sourceware.org/git/?p=glibc.git;a=blob;f=string/memc..., it even copies “whole pages from SRCP to DSTP by virtual address manipulation, as much as possible”. strlen doesn’t do things the K&R way either anymore. It checks one byte at a time until things are word aligned, then checks words for zero bytes. That can read from past the string, so it requires the platform it runs on to make that OK. See https://sourceware.org/git/?p=glibc.git;a=blob;f=string/strlen.c;h=8ce131848710f0aa8fce0d9d12d6198cc6f0c613;hb=refs/heads/release/2.28/master https://sourceware.org/git/?p=glibc.git;a=blob;f=string/strl...)