+
+ $shrunk = 0;
+ # take a value after the current offset
+ if ((my $after = $offset + $context - $enlarged) < $#$self) {
+ # see how much of it matches the current link
+ my $trim = 1;
+ for my $match (split //, $self->[$after]) {
+ scalar $link =~ /\G\Q$match/g or last;
+ $trim++;
+ }
+ # use this link if it's shorter
+ if ($trim < length $link) {
+ $link = substr $self->[$after], 0, $trim;
+ # advance lookbehind offset on the next page
+ $penalty = 0;
+ for ($offset .. $#$self) {
+ last if $self->[$offset + $shrunk] =~ /^\Q$link/;
+ $shrunk++;
+ }
+ }
+ }
+ $enlarged = $penalty;