mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 15:40:19 +00:00
LibC: Relax memmove()
to memcpy()
in more cases
`memcpy()` and `memmove()` are functionally equivalent if the source and destination memory regions do not overlap. If this is the case, we should prefer `memcpy()` as it's implemented in a simpler and faster way. As our `memcpy()` starts copying from the lowest address first, relaxing a `memmove()` call to `memcpy()` is safe if the destination: - starts at a lower address than the source - starts at a higher address than the source's end
This commit is contained in:
parent
176baf7cdb
commit
210448b6ed
Notes:
sideshowbarker
2024-07-17 02:55:44 +09:00
Author: https://github.com/BertalanD Commit: https://github.com/SerenityOS/serenity/commit/210448b6ed Pull-request: https://github.com/SerenityOS/serenity/pull/19859 Reviewed-by: https://github.com/gmta ✅ Reviewed-by: https://github.com/kleinesfilmroellchen ✅
1 changed files with 2 additions and 0 deletions
|
@ -167,6 +167,8 @@ void* memset(void* dest_ptr, int c, size_t n)
|
|||
// https://pubs.opengroup.org/onlinepubs/9699919799/functions/memmove.html
|
||||
void* memmove(void* dest, void const* src, size_t n)
|
||||
{
|
||||
if (dest < src)
|
||||
return memcpy(dest, src, n);
|
||||
if (((FlatPtr)dest - (FlatPtr)src) >= n)
|
||||
return memcpy(dest, src, n);
|
||||
|
||||
|
|
Loading…
Reference in a new issue