diff options
author | Herbert Valerio Riedel <hvr@gnu.org> | 2014-01-03 22:58:32 +0100 |
---|---|---|
committer | Herbert Valerio Riedel <hvr@gnu.org> | 2014-01-03 22:58:32 +0100 |
commit | f9c2888d55408cc442dc3665e66386643fc5fae7 (patch) | |
tree | 75e2ba4495a9a97cadc786e01877bbafcba8814d /libraries/integer-gmp/cbits/alloc.c | |
parent | 4cc6785ab434e781be40e88b27a36c490d257323 (diff) | |
download | haskell-f9c2888d55408cc442dc3665e66386643fc5fae7.tar.gz |
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 <hvr@gnu.org>
Diffstat (limited to 'libraries/integer-gmp/cbits/alloc.c')
-rw-r--r-- | libraries/integer-gmp/cbits/alloc.c | 18 |
1 files changed, 5 insertions, 13 deletions
diff --git a/libraries/integer-gmp/cbits/alloc.c b/libraries/integer-gmp/cbits/alloc.c index 1e2d56b19b..e7111109c7 100644 --- a/libraries/integer-gmp/cbits/alloc.c +++ b/libraries/integer-gmp/cbits/alloc.c @@ -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 |