From: Nicholas Clark Date: Sat, 13 Feb 2010 09:05:18 +0000 (+0000) Subject: Remove redundant hv_exists() calls from ithread_create()'s spec parser. X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=b1faab355535118c9fb99fcc343501012923ece2;p=p5sagit%2Fp5-mst-13.2.git 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. --- diff --git a/dist/threads/threads.xs b/dist/threads/threads.xs index e83da94..f341b6f 100755 --- a/dist/threads/threads.xs +++ b/dist/threads/threads.xs @@ -994,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': @@ -1024,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; }