Commits

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

Optimization: _current_path() is now cached.

  • Participants
  • Parent commits e95e5d4
  • Branches experimental-optimizations-1

Comments (0)

Files changed (2)

     a function whose return value is dereferenced and flatted.
     - A small optimization - now caching the results of _current_components
     inside an accessor and updating it upon every change.
+    - 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.
 
 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

        )))
     {
         $top->_current_components()->[-1] = $self->_curr_file();
+        $top->_calc_curr_path();
+
         $self->_reset_actions();
         return 1;
     } else {
         (map { $_ => $_ } 
         (qw(
             _current_components
+            _current_path
             _dir_stack
             item_obj
             _targets
     return !S_ISDIR( shift->_curr_mode() );
 }
 
-sub _current_path
+# Calculates _current_path from $self->_current_components().
+# Must be called whenever _current_components is modified.
+sub _calc_curr_path
 {
     my $self = shift;
 
-    return File::Spec->catfile(@{$self->_current_components()});
+    $self->_current_path(File::Spec->catfile(@{$self->_current_components()}));
+
+    return;
 }
 
 sub _calc_current_item_obj {
 
     my $target = $self->_curr_file($self->_calc_next_target());
     @{$self->_current_components()} = ($target);
+    $self->_calc_curr_path();
 
     return $target;
 }
     {
         splice(@$st, $father->idx()+1);
         splice(@{$self->_current_components()}, $father->idx()+2);
+        
+        # If depth is false, then we no longer need the _current_path
+        # of the directories above the previously-set value, because we 
+        # already traversed them.
+        if ($self->depth())
+        {
+            $self->_calc_curr_path();
+        }
     }
 
     return 0;