Commits

shl...@6f433eb9-a002-0410-945b-ee5462c261ee  committed a4fe073

Optimized/Refactored the _actions() handling.

  • Participants
  • Parent commits 6af9de6
  • Branches experimental-optimizations-1

Comments (0)

Files changed (3)

     - A small optimization - now caching the results of _current_path()
     upon every modification of _current_components, so File::Spec->catfile()
     won't be called excessively.
+    - Optimization/Refactoring - changed the actions() handling so instead
+    of having the indices, we calculate an array of master actions at
+    start that correspond with the depth() parameter, and then assign it for
+    each PathComponent object in turn based on $top. This is instead of 
+    the indexes and explicit calculations etc., which was both messier
+    and slower.
 
 0.1.5 - Sat Jan  3 17:17:31 IST 2009
     - Unified the two calls to stat() (and several calls to other file

File lib/File/Find/Object.pm

 
     $from->_dir($self->_dir_copy());
 
-    $self->_reset_actions();
+    $top->_fill_actions($self);
 
     push @{$top->_current_components()}, "";
 
         $top->_current_components()->[-1] = $self->_curr_file();
         $top->_calc_curr_path();
 
-        $self->_reset_actions();
+        $top->_fill_actions($self);
+
         return 1;
-    } else {
+    }
+    else {
         return 0;
     }
 }
         (qw(
             _current_components
             _current_path
+            _def_actions
             _dir_stack
             item_obj
             _targets
     }
     $tree->_targets(\@targets);
     $tree->_target_index(-1);
-    $tree->_reset_actions();
+
+    $tree->_calc_default_actions();
+
+    $tree->_fill_actions($tree);
 
     $tree->_last_dir_scanned(undef);
 
     {
         if (-e $self->_move_to_next_target())
         {
-            $self->_reset_actions();
+            $self->_fill_actions($self);
             return 1;
         }
     }
     return 0;
 }
 
-sub _calc_actions
-{
+sub _calc_default_actions {
     my $self = shift;
 
     my @actions = qw(_handle_callback _recurse);
 
-    if ($self->depth())
-    {
-        @actions = reverse(@actions);
-    }
-    return ("_mystat", @actions);
+    $self->_def_actions(
+        ["_mystat", ($self->depth() ? reverse(@actions) : @actions)]
+    );
+
+    return;
+}
+
+sub _fill_actions {
+    my $self = shift;
+    my $other = shift;
+
+    $other->_actions([ @{$self->_def_actions()} ]);
+
+    return;
 }
 
 sub _mystat {
     return "SKIP";
 }
 
-sub _get_real_action
-{
-    my $self = shift;
-    my $action = shift;
-
-    return ($self->_calc_actions())[$action];
-}
-
-sub _shift_current_action
-{
+sub _next_action {
     my $self = shift;
 
-    my $action_proto = shift(@{$self->_current->_actions()});
-
-    if (!defined($action_proto))
-    {
-        return;
-    }
-    else
-    {
-        return $self->_get_real_action($action_proto);
-    }
+    return shift(@{$self->_current->_actions()});
 }
 
 sub _check_process_current {
 {
     my $self = shift;
 
-    while (my $action = $self->_shift_current_action())
+    while (my $action = $self->_next_action())
     {
         my $status = $self->$action();
 

File lib/File/Find/Object/Base.pm

     return shift->_stat_ret->[1];
 }
 
-sub _reset_actions
-{
-    my $self = shift;
-
-    $self->_actions([0,1,2]);
-}
-
 sub _dir_as_string
 {
     my $self = shift;