Tim Bunce wrote:
On Thu, Feb 27, 2003 at 03:04:36PM +1100, Stas Bekman wrote:

As I was looking through DBI.xs, I've noticed that dbi_get_attr_k is a very long if/elseif flow. Wouldn't converting it to use switch(*key) (on the first letter) make things a bit faster? Or is the Perl overhead so much more significant that it doesn't worth the effort?


I'm not sure it's really worth the effort, but you're welcome to :)


the only issue is the last else {} block, which I thought could be split of and run if valuesv is undef, but I see that at least RowsInCache may set it to this value, so this won't work. The alternative solution is use goto() to break out ;)


Just init valuesv to Nullsv, add a few valuesv = &sv_undef's in a
few places where an attribute has been recognised but not set,
then you can test for if (!valuesv) at the end.

I've attached the whole dbi_get_attr_k rather than posting diff, since it won't be useful for reading anyways. and I didn't inlined since I'm afraid my mail agent will mess it up.

Notice that I've tried to do the group by htype, but I didn't know where the attrs with no check for htype belong to, so I couldn't do if/else if/else, but had to do separate if()'s. Also there were a few cases with 'htype <= DBIt_DB' requiring a special case.

I've also duplicated the code from

    /* these are here but are, sadly, not called because not-preloading */
    /* them into the handle attrib cache caused wierdness in t/proxy.t  */
    /* that I never got to the bottom of. One day maybe.                */
    else if (  (htype==DBIt_ST && keylen==8 && strEQ(key, "Database"))
            || (htype==DBIt_DB && keylen==6 && strEQ(key, "Driver"))
    ) {
        D_imp_from_child(imp_dbh, imp_dbh_t, imp_xxh);
        valuesv = newRV((SV*)DBIc_MY_H(imp_dbh));
        cacheit = FALSE;  /* else create ref loop */
    }

as I've moved each attr to its group.

Also I wasn't sure whether I should now remove the checks for keylen, but I've kept them in, since they were already there. Feel free to remove them where they don't make sense.

In any case, now that it's a switch/case construct it should be easy to further perfect the organization.


__________________________________________________________________ Stas Bekman JAm_pH ------> Just Another mod_perl Hacker http://stason.org/ mod_perl Guide ---> http://perl.apache.org mailto:[EMAIL PROTECTED] http://use.perl.org http://apacheweek.com http://modperlbook.org http://apache.org http://ticketmaster.com

Attachment: attr
Description: application/java-vm



Reply via email to