In perl.git, the branch blead has been updated

<http://perl5.git.perl.org/perl.git/commitdiff/39f3f7f442aed93239540238d19a15f6020da747?hp=e77da3b2183d0f9c5ea81dc5780d9a480fc4fa88>

- Log -----------------------------------------------------------------
commit 39f3f7f442aed93239540238d19a15f6020da747
Author: Nicholas Clark <[email protected]>
Date:   Tue Feb 23 20:35:29 2010 +0000

    PL_endav can be NULL, so in S_ithread_create() no need to set it to newAV().

M       dist/threads/threads.xs

commit b1faab355535118c9fb99fcc343501012923ece2
Author: Nicholas Clark <[email protected]>
Date:   Sat Feb 13 09:05:18 2010 +0000

    Remove redundant hv_exists() calls from ithread_create()'s spec parser.
    
    hv_fetch(..., 0) won't create the element if it doesn't exist, returning a 
NULL
    pointer, so hv_exists() and hv_fetch() is doing two hash lookups where one 
would
    suffice.
    
    On this machine, reduces the object code by 3K, about 7%. Everyone's a 
winner.

M       dist/threads/threads.xs

commit 4cf5eae5e58faebb6ae9e68e493cd85343f7a76c
Author: Nicholas Clark <[email protected]>
Date:   Sat Feb 13 08:31:55 2010 +0000

    Change S_ithread_create() params from a single AV* to a pair of SV** 
pointers.
    
    This saves creating, duplicating and freeing and AV, which is only ever 
used for
    an internal calling convention.

M       dist/threads/threads.xs

commit 78b7eff23b1757f7fccef902e7e706080a997e2c
Author: Nicholas Clark <[email protected]>
Date:   Sat Feb 13 08:01:45 2010 +0000

    In threads.xs, convert thread->params from RV to AV.
    
    Pass around and store the array directly, rather than creating, holding and
    dereferencing a reference to it.

M       dist/threads/threads.xs
-----------------------------------------------------------------------

Summary of changes:
 dist/threads/threads.xs |   78 ++++++++++++++++++++++++++---------------------
 1 files changed, 43 insertions(+), 35 deletions(-)

diff --git a/dist/threads/threads.xs b/dist/threads/threads.xs
index b0f7dc8..a559595 100755
--- a/dist/threads/threads.xs
+++ b/dist/threads/threads.xs
@@ -71,7 +71,7 @@ typedef struct _ithread {
     int state;                  /* Detached, joined, finished, etc. */
     int gimme;                  /* Context of create */
     SV *init_function;          /* Code to run */
-    SV *params;                 /* Args to pass function */
+    AV *params;                 /* Args to pass function */
 #ifdef WIN32
     DWORD  thr;                 /* OS's idea if thread id */
     HANDLE handle;              /* OS's waitable handle */
@@ -215,7 +215,7 @@ S_ithread_clear(pTHX_ ithread *thread)
         S_ithread_set(aTHX_ thread);
 
         SvREFCNT_dec(thread->params);
-        thread->params = Nullsv;
+        thread->params = NULL;
 
         if (thread->err) {
             SvREFCNT_dec(thread->err);
@@ -487,7 +487,7 @@ S_ithread_run(void * arg)
     PL_perl_destruct_level = 2;
 
     {
-        AV *params = (AV *)SvRV(thread->params);
+        AV *params = thread->params;
         int len = (int)av_len(params)+1;
         int ii;
 
@@ -675,10 +675,13 @@ S_ithread_create(
         IV        stack_size,
         int       gimme,
         int       exit_opt,
-        SV       *params)
+        SV      **params_start,
+        SV      **params_end)
 {
     ithread     *thread;
     ithread     *current_thread = S_ithread_get(aTHX);
+    AV          *params;
+    SV          **array;
 
 #if PERL_VERSION <= 8 && PERL_SUBVERSION <= 7
     SV         **tmps_tmp = PL_tmps_stack;
@@ -781,7 +784,7 @@ S_ithread_create(
          * they are created
          */
         SvREFCNT_dec(PL_endav);
-        PL_endav = newAV();
+        PL_endav = NULL;
 
         clone_param.flags = 0;
         if (SvPOK(init_function)) {
@@ -792,8 +795,13 @@ S_ithread_create(
                 SvREFCNT_inc(sv_dup(init_function, &clone_param));
         }
 
-        thread->params = sv_dup(params, &clone_param);
-        SvREFCNT_inc_void(thread->params);
+        thread->params = params = newAV();
+        av_extend(params, params_end - params_start - 1);
+        AvFILLp(params) = params_end - params_start - 1;
+        array = AvARRAY(params);
+        while (params_start < params_end) {
+            *array++ = SvREFCNT_inc(sv_dup(*params_start++, &clone_param));
+        }
 
 #if PERL_VERSION <= 8 && PERL_SUBVERSION <= 7
         /* The code below checks that anything living on the tmps stack and
@@ -908,7 +916,6 @@ S_ithread_create(
 #endif
         /* Must unlock mutex for destruct call */
         MUTEX_UNLOCK(&MY_POOL.create_destruct_mutex);
-        sv_2mortal(params);
         thread->state |= PERL_ITHR_NONVIABLE;
         S_ithread_free(aTHX_ thread);   /* Releases MUTEX */
 #ifndef WIN32
@@ -924,7 +931,6 @@ S_ithread_create(
     }
 
     MY_POOL.running_threads++;
-    sv_2mortal(params);
     return (thread);
 }
 
@@ -942,7 +948,6 @@ ithread_create(...)
         char *classname;
         ithread *thread;
         SV *function_to_call;
-        AV *params;
         HV *specs;
         IV stack_size;
         int context;
@@ -950,7 +955,8 @@ ithread_create(...)
         SV *thread_exit_only;
         char *str;
         int idx;
-        int ii;
+        SV **args_start;
+        SV **args_end;
         dMY_POOL;
     CODE:
         if ((items >= 2) && SvROK(ST(1)) && SvTYPE(SvRV(ST(1)))==SVt_PVHV) {
@@ -988,18 +994,19 @@ ithread_create(...)
 
         context = -1;
         if (specs) {
+            SV **svp;
             /* stack_size */
-            if (hv_exists(specs, "stack", 5)) {
-                stack_size = SvIV(*hv_fetch(specs, "stack", 5, 0));
-            } else if (hv_exists(specs, "stacksize", 9)) {
-                stack_size = SvIV(*hv_fetch(specs, "stacksize", 9, 0));
-            } else if (hv_exists(specs, "stack_size", 10)) {
-                stack_size = SvIV(*hv_fetch(specs, "stack_size", 10, 0));
+            if ((svp = hv_fetch(specs, "stack", 5, 0))) {
+                stack_size = SvIV(*svp);
+            } else if ((svp = hv_fetch(specs, "stacksize", 9, 0))) {
+                stack_size = SvIV(*svp);
+            } else if ((svp = hv_fetch(specs, "stack_size", 10, 0))) {
+                stack_size = SvIV(*svp);
             }
 
             /* context */
-            if (hv_exists(specs, "context", 7)) {
-                str = (char *)SvPV_nolen(*hv_fetch(specs, "context", 7, 0));
+            if ((svp = hv_fetch(specs, "context", 7, 0))) {
+                str = (char *)SvPV_nolen(*svp);
                 switch (*str) {
                     case 'a':
                     case 'A':
@@ -1018,27 +1025,27 @@ ithread_create(...)
                     default:
                         Perl_croak(aTHX_ "Invalid context: %s", str);
                 }
-            } else if (hv_exists(specs, "array", 5)) {
-                if (SvTRUE(*hv_fetch(specs, "array", 5, 0))) {
+            } else if ((svp = hv_fetch(specs, "array", 5, 0))) {
+                if (SvTRUE(*svp)) {
                     context = G_ARRAY;
                 }
-            } else if (hv_exists(specs, "list", 4)) {
-                if (SvTRUE(*hv_fetch(specs, "list", 4, 0))) {
+            } else if ((svp = hv_fetch(specs, "list", 4, 0))) {
+                if (SvTRUE(*svp)) {
                     context = G_ARRAY;
                 }
-            } else if (hv_exists(specs, "scalar", 6)) {
-                if (SvTRUE(*hv_fetch(specs, "scalar", 6, 0))) {
+            } else if ((svp = hv_fetch(specs, "scalar", 6, 0))) {
+                if (SvTRUE(*svp)) {
                     context = G_SCALAR;
                 }
-            } else if (hv_exists(specs, "void", 4)) {
-                if (SvTRUE(*hv_fetch(specs, "void", 4, 0))) {
+            } else if ((svp = hv_fetch(specs, "void", 4, 0))) {
+                if (SvTRUE(*svp)) {
                     context = G_VOID;
                 }
             }
 
             /* exit => thread_only */
-            if (hv_exists(specs, "exit", 4)) {
-                str = (char *)SvPV_nolen(*hv_fetch(specs, "exit", 4, 0));
+            if ((svp = hv_fetch(specs, "exit", 4, 0))) {
+                str = (char *)SvPV_nolen(*svp);
                 exit_opt = (*str == 't' || *str == 'T')
                                     ? PERL_ITHR_THREAD_EXIT_ONLY : 0;
             }
@@ -1050,11 +1057,11 @@ ithread_create(...)
         }
 
         /* Function args */
-        params = newAV();
+        args_start = &ST(idx + 2);
         if (items > 2) {
-            for (ii=2; ii < items ; ii++) {
-                av_push(params, SvREFCNT_inc(ST(idx+ii)));
-            }
+            args_end = &ST(idx + items);
+        } else {
+            args_end = args_start;
         }
 
         /* Create thread */
@@ -1063,7 +1070,8 @@ ithread_create(...)
                                         stack_size,
                                         context,
                                         exit_opt,
-                                        newRV_noinc((SV*)params));
+                                        args_start,
+                                        args_end);
         if (! thread) {
             XSRETURN_UNDEF;     /* Mutex already unlocked */
         }
@@ -1236,7 +1244,7 @@ ithread_join(...)
             PerlInterpreter *other_perl;
             CLONE_PARAMS clone_params;
 
-            params_copy = (AV *)SvRV(thread->params);
+            params_copy = thread->params;
             other_perl = thread->interp;
             clone_params.stashes = newAV();
             clone_params.flags = CLONEf_JOIN_IN;

--
Perl5 Master Repository

Reply via email to