[commit: packages/integer-gmp] master: Refactor `stgReallocForGMP` to use `memcpy` (66ea120)
git at git.haskell.org
git at git.haskell.org
Fri Jan 3 22:17:55 UTC 2014
Repository : ssh://git@git.haskell.org/integer-gmp
On branch : master
Link : http://git.haskell.org/packages/integer-gmp.git/commitdiff/66ea120f3a31ba8d81556fa121f9b998eef570b8
>---------------------------------------------------------------
commit 66ea120f3a31ba8d81556fa121f9b998eef570b8
Author: Herbert Valerio Riedel <hvr at gnu.org>
Date: Fri Jan 3 22:58:32 2014 +0100
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 at gnu.org>
>---------------------------------------------------------------
66ea120f3a31ba8d81556fa121f9b998eef570b8
cbits/alloc.c | 18 +++++-------------
1 file changed, 5 insertions(+), 13 deletions(-)
diff --git a/cbits/alloc.c b/cbits/alloc.c
index 1e2d56b..e711110 100644
--- a/cbits/alloc.c
+++ b/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
More information about the ghc-commits
mailing list