This is the mail archive of the mailing list for the glibc project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[RFC] Do not call memmove when memcpy suffices.


We in memmove currently do lot of custom logic that is not neccessary
for most of time. When strings do not overlap we could and should just
call memcpy.

One way to do this is to add check for overlap before all memmove calls.
This allows user to just install new glibc without recompiling.

Other way is also possible, as distributions often ship old glibc
version we could modify header and developers can recompile without
worrying if user upgrades.

For header version I prepared following macro but where should I put it?

A most likely place is string/bits/string2.h but I am not quite sure.


#define memmove(_dest, _src, _n)                                              \
  ({                                                                          \
     char *dest = (_dest);                                                    \
     char *src = (_src);                                                      \
     size_t n = (_n);                                                         \
     if (__glibc_likely ((size_t)((src - n) - dest) >= 2 * n))                \
       return memcpy (dest, src, n);                                          \
     else                                                                     \
       return memmove (dest, src, n);                                         \

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]