This is an automated email from the git hooks/post-receive script.

ppm-guest pushed a commit to annotated tag v0.36
in repository libmath-prime-util-perl.

commit d7eee04823f8519dd49902ab941ee16b168b78e9
Author: Dana Jacobsen <d...@acm.org>
Date:   Mon Dec 30 11:48:32 2013 -0800

    Remove redundancy in inner loop of forprimes/forcomposites/fordivisors
---
 Changes |  2 ++
 XS.xs   | 20 ++++++++------------
 2 files changed, 10 insertions(+), 12 deletions(-)

diff --git a/Changes b/Changes
index 3358497..12125db 100644
--- a/Changes
+++ b/Changes
@@ -25,6 +25,8 @@ Revision history for Perl module Math::Prime::Util
 
     - Lots of XS interface reorgs.
 
+    - XS reduncies and fixes from bulk88 and leont.
+
     - Speedup for input number validation: speedup for all functions,
       especially noticeable with fast functions (e.g. small n is_prime(n)).
 
diff --git a/XS.xs b/XS.xs
index 8a2e484..bb862fc 100644
--- a/XS.xs
+++ b/XS.xs
@@ -718,7 +718,7 @@ forprimes (SV* block, IN SV* svbeg, IN SV* svend = 0)
 #if !USE_MULTICALL
     dSP;
     PUSHMARK(SP);
-    XPUSHs(block); XPUSHs(svbeg); XPUSHs(svend);
+    XPUSHs(block); XPUSHs(svbeg); if (svend) XPUSHs(svend);
     PUTBACK;
     (void) call_pv("Math::Prime::Util::_generic_forprimes", G_VOID|G_DISCARD);
     SPAGAIN;
@@ -735,7 +735,7 @@ forprimes (SV* block, IN SV* svbeg, IN SV* svend = 0)
     if (!_validate_int(svbeg, 0) || (items >= 3 && !_validate_int(svend,0))) {
       dSP;
       PUSHMARK(SP);
-      XPUSHs(block); XPUSHs(svbeg); XPUSHs(svend);
+      XPUSHs(block); XPUSHs(svbeg); if (svend) XPUSHs(svend);
       PUTBACK;
       (void) call_pv("Math::Prime::Util::_generic_forprimes", 
G_VOID|G_DISCARD);
       SPAGAIN;
@@ -756,13 +756,13 @@ forprimes (SV* block, IN SV* svbeg, IN SV* svend = 0)
       croak("Not a subroutine reference");
     SAVESPTR(GvSV(PL_defgv));
     svarg = newSVuv(0);
+    GvSV(PL_defgv) = svarg;
     /* Handle early part */
     while (beg < 6) {
       dSP;
       beg = (beg <= 2) ? 2 : (beg <= 3) ? 3 : 5;
       if (beg <= end) {
         sv_setuv(svarg, beg);
-        GvSV(PL_defgv) = svarg;
         PUSHMARK(SP);
         call_sv((SV*)cv, G_VOID|G_DISCARD);
       }
@@ -783,7 +783,6 @@ forprimes (SV* block, IN SV* svbeg, IN SV* svend = 0)
       PUSH_MULTICALL(cv);
       for (beg = _XS_next_prime(beg-1); beg <= end && beg != 0; beg = 
_XS_next_prime(beg)) {
         sv_setuv(svarg, beg);
-        GvSV(PL_defgv) = svarg;
         MULTICALL;
       }
       FIX_MULTICALL_REFCOUNT;
@@ -797,7 +796,6 @@ forprimes (SV* block, IN SV* svbeg, IN SV* svend = 0)
           PUSH_MULTICALL(cv);
           START_DO_FOR_EACH_SIEVE_PRIME( segment, seg_low - seg_base, seg_high 
- seg_base ) {
             sv_setuv(svarg, seg_base + p);
-            GvSV(PL_defgv) = svarg;
             MULTICALL;
           } END_DO_FOR_EACH_SIEVE_PRIME
           FIX_MULTICALL_REFCOUNT;
@@ -806,7 +804,6 @@ forprimes (SV* block, IN SV* svbeg, IN SV* svend = 0)
           START_DO_FOR_EACH_SIEVE_PRIME( segment, seg_low - seg_base, seg_high 
- seg_base ) {
             dSP;
             sv_setuv(svarg, seg_base + p);
-            GvSV(PL_defgv) = svarg;
             PUSHMARK(SP);
             call_sv((SV*)cv, G_VOID|G_DISCARD);
           } END_DO_FOR_EACH_SIEVE_PRIME
@@ -836,7 +833,7 @@ forcomposites (SV* block, IN SV* svbeg, IN SV* svend = 0)
     if (!_validate_int(svbeg, 0) || (items >= 3 && !_validate_int(svend,0))) {
       dSP;
       PUSHMARK(SP);
-      XPUSHs(block); XPUSHs(svbeg); XPUSHs(svend);
+      XPUSHs(block); XPUSHs(svbeg); if (svend) XPUSHs(svend);
       PUTBACK;
       (void) call_pv("Math::Prime::Util::_generic_forcomposites", 
G_VOID|G_DISCARD);
       SPAGAIN;
@@ -855,6 +852,7 @@ forcomposites (SV* block, IN SV* svbeg, IN SV* svend = 0)
 
     SAVESPTR(GvSV(PL_defgv));
     svarg = newSVuv(0);
+    GvSV(PL_defgv) = svarg;
 #if USE_MULTICALL
     if (!CvISXSUB(cv) && (end-beg) > 200) {
       unsigned char* segment;
@@ -864,7 +862,7 @@ forcomposites (SV* block, IN SV* svbeg, IN SV* svend = 0)
       I32 gimme = G_VOID;
       PUSH_MULTICALL(cv);
       if (beg <= 4) { /* sieve starts at 7, so handle this here */
-        sv_setuv(svarg, 4);  GvSV(PL_defgv) = svarg;  MULTICALL;
+        sv_setuv(svarg, 4);  MULTICALL;
         beg = 6;
       }
       /* Find the two primes that bound their interval. */
@@ -878,7 +876,7 @@ forcomposites (SV* block, IN SV* svbeg, IN SV* svend = 0)
           prevprime = seg_base + p;
           cend = (prevprime-1 > end)   ? end : prevprime-1;
           for (c = cbeg; c <= cend; c++) {
-            sv_setuv(svarg, c);  GvSV(PL_defgv) = svarg;  MULTICALL;
+            sv_setuv(svarg, c);  MULTICALL;
           }
         } END_DO_FOR_EACH_SIEVE_PRIME
       }
@@ -895,7 +893,6 @@ forcomposites (SV* block, IN SV* svbeg, IN SV* svend = 0)
         if (!_XS_is_prob_prime(beg)) {
           dSP;
           sv_setuv(svarg, beg);
-          GvSV(PL_defgv) = svarg;
           PUSHMARK(SP);
           call_sv((SV*)cv, G_VOID|G_DISCARD);
         }
@@ -935,6 +932,7 @@ fordivisors (SV* block, IN SV* svn)
 
     SAVESPTR(GvSV(PL_defgv));
     svarg = newSVuv(0);
+    GvSV(PL_defgv) = svarg;
 #if USE_MULTICALL
     if (!CvISXSUB(cv)) {
       dMULTICALL;
@@ -942,7 +940,6 @@ fordivisors (SV* block, IN SV* svn)
       PUSH_MULTICALL(cv);
       for (i = 0; i < ndivisors; i++) {
         sv_setuv(svarg, divs[i]);
-        GvSV(PL_defgv) = svarg;
         MULTICALL;
       }
       FIX_MULTICALL_REFCOUNT;
@@ -954,7 +951,6 @@ fordivisors (SV* block, IN SV* svn)
       for (i = 0; i < ndivisors; i++) {
         dSP;
         sv_setuv(svarg, divs[i]);
-        GvSV(PL_defgv) = svarg;
         PUSHMARK(SP);
         call_sv((SV*)cv, G_VOID|G_DISCARD);
       }

-- 
Alioth's /usr/local/bin/git-commit-notice on 
/srv/git.debian.org/git/pkg-perl/packages/libmath-prime-util-perl.git

_______________________________________________
Pkg-perl-cvs-commits mailing list
Pkg-perl-cvs-commits@lists.alioth.debian.org
http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/pkg-perl-cvs-commits

Reply via email to