Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggestion for get_list_and #5

Open
remorse opened this issue Feb 23, 2016 · 1 comment
Open

Suggestion for get_list_and #5

remorse opened this issue Feb 23, 2016 · 1 comment

Comments

@remorse
Copy link

remorse commented Feb 23, 2016

Hi! You have a comment in your source code for get_list_and that asks for patches. This isn't quite a patch, but it's a slightly different take on the problem which gets rid of the ugly preprocessing for @items.

    my $start = $self->{'list'}{'start'};
    $start =~ s/\{([01])\}/$items[$1]/g;
    shift @items;
    $items[0] = $start;

    while(@items > 2) {
        my $middle = $self->{'list'}{'middle'};
        $middle =~ s/\{([01])\}/$items[$1]/g;
        shift @items;
        $items[0] = $middle;
    }

    my $end = $self->{'list'}{'end'};
    $end =~ s/\{([01])\}/$items[$1]/g;

    return $end;
@remorse
Copy link
Author

remorse commented Feb 23, 2016

Hi! I just remembered about splice. You can replace the lines:

    shift @items;
    $items[0] = $var;

with

    splice(@items, 0, 2, $var);

where $var is either $start or $middle.

I have a vague memory of someone telling me that this may be more performant as well, but I don't know if that is true.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant