Commits

Anonymous committed 16162e2

Small optimization for the _st flag.

  • Participants
  • Parent commits 5ec7dba
  • Branches experimental-optimizations-1

Comments (0)

Files changed (2)

     of Class::Accessor. After consulting Devel::NYTProf, it seemed that
     the majority of the time of a simple File-Find-Object scan was spent
     in Class::Accessor. Hopefully, this will make F-F-O run faster.
+    - A small optimization - added a flag to $self with whether the stack
+    is full or not. This is used inside _top_it() and _is_top().
 
 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

                 my $non = "_non_top_$m";
                 sub {
                     my $self = shift;
-                    return $self->_is_top()
-                        ? $self->$top(@_)
-                        : $self->$non(@_)
+                    return exists($self->{_st})
+                        ? $self->$non(@_)
+                        : $self->$top(@_)
                         ;
                 };
             };
 sub new {
     my ($class, $options, @targets) = @_;
 
+    # The *existence* of a _st key inside the struct
+    # indicates that the stack is full.
+    # So now it's empty.
     my $tree = {
-        
         _dir_stack => [],
     };
 
 {
     my $self = shift;
 
-    return ! @{$self->_dir_stack()};
+    return ! exists($self->{_st});
 }
 
 sub _curr_mode {
 
     my $father = $self->_current_father;
 
+    my $st = $self->_dir_stack();
+
     if ($self eq $father)
     {
-        @{$self->_dir_stack()} = ();
+        @$st = ();
+        delete($self->{_st});
     }
     else
     {
-        while (scalar(@{$self->_dir_stack()}) != $father->idx() + 1)
-        {
-            $self->_pop_item();
-        }
+        splice(@$st, $father->idx()+1);
     }
 
     return 0;
 }
 
-sub _pop_item
-{
-    my $self = shift;
-
-    pop(@{$self->_dir_stack()});
-
-    return;
-}
-
 sub _calc_actions
 {
     my $self = shift;
             scalar(@{$self->_dir_stack()})
         );
 
+    $self->{_st} = 1;
+
     return 0;
 }