Commits

Anonymous committed ba04b42

Optimization: optimized the loop detection by having hash lookups.

- Optimization: optimized the loop detection by having a hash lookup
of inodes in each path component, that are built incrementally and checked
for every subsequent node.

  • Participants
  • Parent commits aaaab26

Comments (0)

Files changed (3)

     - Added use integer to the modules, because they don't make use
     of floating-point calculation. It may be a minor optimization, but then
     again it may be not.
+    - Optimization: optimized the loop detection by having a hash lookup 
+    of inodes in each path component, that are built incrementally and checked
+    for every subsequent node.
 
 0.1.8 - Mon Jan 19 18:36:51 IST 2009
     - Optimization/Refactoring: replaced the last call to ->_father with a 

File lib/File/Find/Object.pm

     $self->_dir([ @{$top->_curr_comps()} ]);
     $self->_stat_ret($top->_top_stat_copy());
 
+    my $inode = $self->_inode();
+    $self->_set_inodes(
+        {
+            %{$from->_inodes()},
+            (
+                ($inode == 0)
+                ? () 
+                : (join(",", $self->_dev(), $inode) 
+                    => 
+                    scalar(@{$top->_dir_stack()})
+                  )
+            )
+        }
+    );
+
     $self->_last_dir_scanned(undef);
 
     $from->_dir($self->_dir_copy());
             $top->_mystat();
             $self->_stat_ret($top->_top_stat_copy());
             $top->_dev($self->_dev);
+
+            my $inode = $self->_inode();
+            $self->_set_inodes(
+                ($inode == 0)
+                ? {}
+                :
+                {
+                    join(",", $self->_dev(), $inode) => 0,
+                },
+            );
+
             return 1;
         }
     }
 sub _is_loop {
     my $self = shift;
 
-    my $s = $self->_top_stat();
-    my $stack = $self->_dir_stack();
+    my $key = join(",", @{$self->_top_stat()}[0,1]);
+    my $lookup = $self->_current->_inodes;
 
-    if (defined(my $ptr = List::Util::first { $_->_is_same_inode($s) } @{$stack}[0 .. $#$stack-1])) {
-        $self->_warn_about_loop($ptr);
+    if (exists($lookup->{$key})) {
+        $self->_warn_about_loop($self->_dir_stack->[$lookup->{$key}]);
         return 1;
     }
     else {

File lib/File/Find/Object/PathComp.pm

                 _traverse_to
             ))
         ) 
-    }
+    },
+    getters => { _inodes => '_inodes' },
+    setters => { _set_inodes => '_inodes' },
     ;
 
 use File::Spec;