Precompile coords regex

main
parent 5361c2dbc4
commit 4c8aa65da2
  1. 12
      wiki-tile.pl

@ -14,6 +14,10 @@ use Data::Dumper;
use feature "signatures";
no warnings "experimental::signatures";
# The below regex is a whitespace forgiving version of /^(-?\d+),(-?\d+)/, an int pair
my $coords_regex = qr/^\s*(-?\s*\d+)\s*,\s*(-?\s*\d+)\s*$/;
my $api_url = "https://wiki.tensor.green/w/api.php";
my $region_template_name = "MapRegion";
my $subregion_template_name = "MapSubregion";
@ -160,9 +164,8 @@ foreach my $page (values %{$tile_query_results->{query}{pages}})
my $region = $grid->{regions}{$region_name};
foreach my $coords (split /;/, $content)
{
# The below regex is a whitespace forgiving version of /^(-?\d+),(-?\d+)/, an int pair
do { carp "Skipping bad spec: $coords"; next; }
unless $coords =~ /^\s*(-?\s*\d+)\s*,\s*(-?\s*\d+)\s*$/;
unless $coords =~ $coords_regex;
$region->make_tile_at($1,$2);
}
}
@ -207,7 +210,7 @@ foreach my $page (values %{$location_query_results->{query}{pages}})
}
# The below regex is a whitespace forgiving version of /^(-?\d+),(-?\d+)/, an int pair
if($parsed_template->{positional_params}[0] =~ /^\s*(-?\s*\d+)\s*,\s*(-?\s*\d+)\s*$/)
if($parsed_template->{positional_params}[0] =~ $coords_regex)
{
$location->make_tile_at($1,$2);
if($regiondir)
@ -215,9 +218,8 @@ foreach my $page (values %{$location_query_results->{query}{pages}})
$location_with_context->make_tile_at($1,$2);
foreach my $coords (split /;/, $parsed_template->{named_params}{context_tiles})
{
# The below regex is a whitespace forgiving version of /^(-?\d+),(-?\d+)/, an int pair
do { carp "Skipping bad spec: $coords"; next; }
unless $coords =~ /^\s*(-?\s*\d+)\s*,\s*(-?\s*\d+)\s*$/;
unless $coords =~ $coords_regex;
$location_with_context->add_tile($grid->get_tile_at($1, $2));
}
}

Loading…
Cancel
Save