[Gmp-commit] /var/hg/gmp: 2 new changesets

mercurial at gmplib.org mercurial at gmplib.org
Thu Dec 6 11:10:55 CET 2012


details:   /var/hg/gmp/rev/bc0460a05698
changeset: 15165:bc0460a05698
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Thu Dec 06 11:09:42 2012 +0100
description:
mpz/{abs,neg}.c: Use NEWALLOC.

details:   /var/hg/gmp/rev/73e97279c978
changeset: 15166:73e97279c978
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Thu Dec 06 11:10:48 2012 +0100
description:
mpz/com.c: Reduce branches.

diffstat:

 ChangeLog |   4 ++++
 mpz/abs.c |   2 +-
 mpz/com.c |  30 +++++++++++++-----------------
 mpz/neg.c |   5 +++--
 4 files changed, 21 insertions(+), 20 deletions(-)

diffs (96 lines):

diff -r 5b84bc52aded -r 73e97279c978 ChangeLog
--- a/ChangeLog	Thu Dec 06 10:33:45 2012 +0100
+++ b/ChangeLog	Thu Dec 06 11:10:48 2012 +0100
@@ -3,6 +3,10 @@
 	* tests/mpq/reuse.c: New test (adapted from mpf/reuse.c).
 	* tests/mpq/Makefile.am (check_PROGRAMS): Add reuse.
 
+	* mpz/abs.c: Use NEWALLOC.
+	* mpz/neg.c: Likewise.
+	* mpz/com.c: Reduce branches.
+	
 2012-12-05  Niels Möller  <nisse at lysator.liu.se>
 
 	* mpn/generic/brootinv.c (mpn_brootinv): Make valgrind happier, at
diff -r 5b84bc52aded -r 73e97279c978 mpz/abs.c
--- a/mpz/abs.c	Thu Dec 06 10:33:45 2012 +0100
+++ b/mpz/abs.c	Thu Dec 06 11:10:48 2012 +0100
@@ -33,7 +33,7 @@
 
   if (u != w)
     {
-      wp = MPZ_REALLOC (w, size);
+      wp = MPZ_NEWALLOC (w, size);
 
       up = PTR (u);
 
diff -r 5b84bc52aded -r 73e97279c978 mpz/com.c
--- a/mpz/com.c	Thu Dec 06 10:33:45 2012 +0100
+++ b/mpz/com.c	Thu Dec 06 11:10:48 2012 +0100
@@ -35,31 +35,27 @@
 	 But this can be simplified using the identity -x = ~x + 1.
 	 So we're going to compute (~~x) + 1 = x + 1!  */
 
-      dst_ptr = MPZ_REALLOC (dst, size + 1);
-
-      src_ptr = PTR (src);
-
       if (UNLIKELY (size == 0))
 	{
 	  /* special case, as mpn_add_1 wants size!=0 */
-	  dst_ptr[0] = 1;
+	  PTR (dst)[0] = 1;
 	  SIZ (dst) = -1;
-	  return;
 	}
+      else
+	{
+	  mp_limb_t cy;
 
-      {
-	mp_limb_t cy;
+	  dst_ptr = MPZ_REALLOC (dst, size + 1);
 
-	cy = mpn_add_1 (dst_ptr, src_ptr, size, (mp_limb_t) 1);
-	if (cy)
-	  {
-	    dst_ptr[size] = cy;
-	    size++;
-	  }
+	  src_ptr = PTR (src);
+
+	  cy = mpn_add_1 (dst_ptr, src_ptr, size, (mp_limb_t) 1);
+	  dst_ptr[size] = cy;
+	  size += (cy != 0);
+
+	  /* Store a negative size, to indicate ones-extension.  */
+	  SIZ (dst) = -size;
       }
-
-      /* Store a negative size, to indicate ones-extension.  */
-      SIZ (dst) = -size;
     }
   else
     {
diff -r 5b84bc52aded -r 73e97279c978 mpz/neg.c
--- a/mpz/neg.c	Thu Dec 06 10:33:45 2012 +0100
+++ b/mpz/neg.c	Thu Dec 06 11:10:48 2012 +0100
@@ -25,7 +25,8 @@
 void
 mpz_neg (mpz_ptr w, mpz_srcptr u)
 {
-  mp_ptr wp, up;
+  mp_ptr wp;
+  mp_srcptr up;
   mp_size_t usize, size;
 
   usize = SIZ (u);
@@ -34,7 +35,7 @@
     {
       size = ABS (usize);
 
-      wp = MPZ_REALLOC (w, size);
+      wp = MPZ_NEWALLOC (w, size);
 
       up = PTR (u);
 


More information about the gmp-commit mailing list