Commits

Anonymous committed e95e5d4

Optimization: caching _current_components.

Comments (0)

Files changed (2)

     reference) and replaced all calls with calls to _current_components().
     - A small optimization - ->dir() instead of ->_dir_copy() for 
     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.
 
 0.1.5 - Sat Jan  3 17:17:31 IST 2009
     - Unified the two calls to stat() (and several calls to other file

lib/File/Find/Object.pm

     my $self = {};
     bless $self, $class;
 
-    $self->_dir($top->_current_components());
+    $self->_dir([ @{$top->_current_components()} ]);
     $self->_stat_ret($top->_top_stat_copy());
 
     $self->idx($index);
 
     $self->_reset_actions();
 
+    push @{$top->_current_components()}, "";
+
     return $top->_open_dir() ? $self : undef;
 }
 
             $top->_father($self)->_next_traverse_to()
        )))
     {
+        $top->_current_components()->[-1] = $self->_curr_file();
         $self->_reset_actions();
         return 1;
     } else {
     accessors => {
         (map { $_ => $_ } 
         (qw(
+            _current_components
             _dir_stack
             item_obj
             _targets
     # So now it's empty.
     my $tree = {
         _dir_stack => [],
+        _current_components => [],
     };
 
     bless($tree, $class);
 sub _calc_current_item_obj {
     my $self = shift;
 
-    my $components = $self->_current_components();
-    my $base = shift(@$components);
+    my @comps = @{$self->_current_components()};
+    my $base = shift(@comps);
     my $stat = $self->_top_stat_copy();
 
     my $path = $self->_current_path();
     my @basename = ();
     if ($self->_curr_not_a_dir())
     {
-        @basename = (basename => pop(@$components));
+        @basename = (basename => pop(@comps));
     }
 
     return File::Find::Object::Result->new(
         {
             @basename,
             path => $path,
-            dir_components => $components,
+            dir_components => \@comps,
             base => $base,
             stat_ret => $stat,
         }
 {
     my $self = shift; 
 
-    return $self->_curr_file($self->_calc_next_target());
+    my $target = $self->_curr_file($self->_calc_next_target());
+    @{$self->_current_components()} = ($target);
+
+    return $target;
 }
 
 sub _move_next
     else
     {
         splice(@$st, $father->idx()+1);
+        splice(@{$self->_current_components()}, $father->idx()+2);
     }
 
     return 0;
     return 1;
 }
 
+=begin Nothing
+
 sub _current_components {
     my $self = shift;
 
     return $self->_current_father->_dir();
 }
 
+=end Nothing
+
+=cut
+
 sub _open_dir {
     my $self = shift;
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.