This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Perl_sv_vcatpvfn_flags: unify int arg fetching
authorDavid Mitchell <davem@iabyn.com>
Fri, 26 May 2017 16:23:09 +0000 (17:23 +0100)
committerDavid Mitchell <davem@iabyn.com>
Wed, 7 Jun 2017 08:11:04 +0000 (09:11 +0100)
commitb154ff054ce4e76402d5ffae3bfd5f169869d153
tree94557a9dafdb985c2f94d5b1aa19d0249803442e
parent14d1b0a5c7c0be5753b05ab19841954438ea1cb7
Perl_sv_vcatpvfn_flags: unify int arg fetching

There are two big blocks of code that do signed and unsigned 'get next int
arg' processing. Combine them (sort of).

Previously it was a bit like

    case 'd':
    case 'i':
        base = 10;
        if (vectorize)
            uv = ...
        else if (arg)
            iv = ...
        else
            iv = SvIV_nomg(argsv);
        if (!vectorize)
            uv = f(iv) for some f.
        goto integer;

    case 'x' base = 16; goto uns_integer;
    case 'u' base = 10; goto uns_integer;
    ...
    uns_integer:
        if (vectorize)
            uv = ...
        else if (arg)
            uv = ...
        else
            uv = SvUV_nomg(argsv);

    integer:
        ... do stuff with base and uv ...

Now it's more like

    case 'd': base = -10; goto get_int_arg_val;
    case 'i': base = -10; goto get_int_arg_val;
    case 'x': base =  16; goto get_int_arg_val;
    case 'u': base =  10; goto get_int_arg_val;

    get_int_arg_val:

        if (vectorize)
            uv = ...
        else if (base < 0) {
            /* signed int type */
            base = -base;
            if (arg)
                iv = ...
            else
                iv = SvIV_nomg(argsv);
            uv = f(iv) for some f.
        }
        else {
            /* unsigned int type */
            if (arg)
                uv = ...
            else
                uv = SvUV_nomg(argsv);
        }

    integer:
        ... do stuff with base and uv ...

Note that in particular the vectorize block of code is no longer
duplicated. This will also allow the next commit to handle Inf/overload
just after the 'get_int_arg_val' label rather than doing it before the
main switch and slowing down the non-integer format types.

Should be no functional changes
sv.c