Skip to content
Snippets Groups Projects
Commit 66ea120f authored by Herbert Valerio Riedel's avatar Herbert Valerio Riedel :man_dancing:
Browse files

Refactor `stgReallocForGMP` to use `memcpy`


GCC is able to generate better code when using `memcpy` instead of
manually copying bytes in a loop. Otoh, `stgAllocForGMP` is typically
called for enlarging initial single-limb structures (see also #8647 for
more information) and so this minor optimization won't be very visible
in measurements.

Signed-off-by: Herbert Valerio Riedel's avatarHerbert Valerio Riedel <hvr@gnu.org>
parent c6f046a3
No related branches found
No related tags found
No related merge requests found
......@@ -4,6 +4,8 @@
*
* ---------------------------------------------------------------------------*/
#include <string.h>
#include "Rts.h"
#include "gmp.h"
......@@ -83,19 +85,9 @@ stgAllocForGMP (size_t size_in_bytes)
void *
stgReallocForGMP (void *ptr, size_t old_size, size_t new_size)
{
size_t min_size;
void *new_stuff_ptr = stgAllocForGMP(new_size);
nat i = 0;
char *p = (char *) ptr;
char *q = (char *) new_stuff_ptr;
min_size = old_size < new_size ? old_size : new_size;
/* TODO: use memcpy */
for (; i < min_size; i++, p++, q++) {
*q = *p;
}
return(new_stuff_ptr);
size_t min_size = old_size < new_size ? old_size : new_size;
return memcpy(stgAllocForGMP(new_size), ptr, min_size);
}
void
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment