Commits

Anonymous committed c5623a0

Optimised _get_next_cells.

This reduced the run time to 10 seconds with --seed=24.

nytprof reported it to consume the lion's share of the time.

  • Participants
  • Parent commits a86cd62

Comments (0)

Files changed (1)

abc-path/generator/generate-abs-path.pl

 
 sub _get_next_cells
 {
-    my ($self, $state, $xy) = @_;
+    my ($self, $state, $init_xy) = @_;
 
     my $l = $state->{layout};
-    my $in_range = sub { my $i = shift; return (($i >= 0) && ($i < $LEN)); };
 
+    my ($sy, $sx) = @{$init_xy}[$Y,$X];
     return
     [ 
-        map {
-        my $m = $_;
-        my $x = $xy->[$X] + $m->[$X];
-        my $y = $xy->[$Y] + $m->[$Y];
-
-        (
-        $in_range->($x) && $in_range->($y) &&
-        (vec($l, $y*$LEN + $x, 8) == 0)
-        ) ? [$y,$x] : ()
-        } ([-1,-1],[-1,0],[-1,1],[0,-1],[0,1],[1,-1],[1,0],[1,1])
+        map
+        {
+            my ($y,$x) = ($sy+$_->[$Y], $sx+$_->[$X]);
+            (
+            (
+                ($x >= 0) && ($x < $LEN) && ($y >= 0) && ($y < $LEN)
+                    &&
+                (vec($l, $y*$LEN + $x, 8) == 0)
+            ) 
+                ? [$y,$x]
+                : ()
+            )
+        } 
+        ([-1,-1],[-1,0],[-1,1],[0,-1],[0,1],[1,-1],[1,0],[1,1])
     ];
 }