X-Git-Url: http://git.shiar.net/perl/list-index.git/blobdiff_plain/97973476dd225680059f6b58a12cef3ef950ffde..b300966772b6cbb9527036400bb1a24808aa5f36:/lib/List/Index.pm diff --git a/lib/List/Index.pm b/lib/List/Index.pm index 6309d2e..f58e43e 100644 --- a/lib/List/Index.pm +++ b/lib/List/Index.pm @@ -60,18 +60,21 @@ sub ranges { if ((my $after = $offset + $lookahead) < $#rows) { # see how much of it matches the current link my $trim = 1; + pos $link = 0; for my $match (split //, $rows[$after]) { scalar $link =~ /\G\Q$match/g or last; $trim++; } # use this link if it's shorter if ($trim < length $link) { - $link = substr $rows[$after], 0, $trim; - # advance lookbehind offset on the next page $enlarged = 0; for ($offset + 1 .. $after) { + my $prefix = substr $rows[$_], 0, $trim; + # advance lookbehind offset on the next page $shrunk++; - last if $rows[$_] =~ /^\Q$link/; + next if $link =~ /^\Q$prefix/; + $link = $prefix; + last; } } }