Commits

Anonymous committed ccc5e68

Unified system calls to disk-access.

- Unified the two calls to stat() (and several calls to other file
operators) in order to reduce the number of system calls/disk accesses
issued by File::Find::Object.

  • Participants
  • Parent commits 8a8af5c

Comments (0)

Files changed (3)

+    - Unified the two calls to stat() (and several calls to other file
+    operators) in order to reduce the number of system calls/disk accesses
+    issued by File::Find::Object.
+
 0.1.4 - Thu Dec 25 18:27:48 IST 2008
     - Bug fix: made sure ->item_obj() is available on the first call
     to the callback() and is properly synchronized with it.

lib/File/Find/Object.pm

     bless $self, $class;
 
     $self->_dir($top->_current_components_copy());
+    $self->_stat_ret($top->_top_stat_copy());
+
     $self->idx($index);
 
     $self->_last_dir_scanned(undef);
 
 use File::Find::Object::Result;
 
+use Fcntl ':mode';
+
 __PACKAGE__->mk_accessors(qw(
     _dir_stack
     item_obj
     _targets
     _target_index
+    _top_stat
 ));
 
 sub _get_options_ids
 
 __PACKAGE__->_make_copy_methods([qw(
     _current_components
+    _top_stat
     )]
 );
 
 
     # If current is not a directory always return 0, because we may
     # be asked to traverse single-files.
-    my @st = stat($self->_current_path());
-    if (!-d _)
+
+    $self->_top_stat([stat($self->_current_path())]);
+
+    if ($self->_is_top()) {
+        # Assign to _stat_ret as well, so the _stat_ret field of the top
+        # item will be set.    
+        $self->_stat_ret($self->_top_stat_copy());
+    }
+
+    if (! S_ISDIR($self->_top_stat->[2]))
     {
         return 0;
     }
     else
     {
-        return $self->_check_subdir_helper(\@st);
+        return $self->_check_subdir_helper();
     }
 }
 
 
 sub _find_ancestor_with_same_inode {
     my $self = shift;
-    my $st = shift;
 
     my $ptr = $self->_current_father;
 
     while($ptr) {
-        if ($ptr->_is_same_inode($st)) {
+        if ($ptr->_is_same_inode($self->_top_stat())) {
             return $ptr;
         }
     }
 
 sub _non_top__check_subdir_helper {
     my $self = shift;
-    my $st = shift;
 
-    if (-l $self->_current_path() && !$self->followlink())
+    if (S_ISLNK($self->_top_stat->[2]) && !$self->followlink())
     {
         return 0;
     }
 
-    if ($st->[0] != $self->_current_father->_dev() && $self->nocrossfs())
+    if (   $self->_top_stat->[0] != $self->_current_father->_dev()
+        && $self->nocrossfs()
+    )
     {
         return 0;
     }
 
-    if (my $ptr = $self->_find_ancestor_with_same_inode($st)) {
+    if (my $ptr = $self->_find_ancestor_with_same_inode()) {
         $self->_warn_about_loop($ptr);
         return 0;
     }

lib/File/Find/Object/Base.pm

 __PACKAGE__->mk_accessors(qw(
     _actions
     _curr_file
-    _dev
     _dir
     _files
     idx
-    _inode
     _last_dir_scanned
     _open_dir_ret
+    _stat_ret
     _traverse_to
 ));
 
     )]
 );
 
+sub _dev
+{
+    return shift->_stat_ret->[0];
+}
+
+sub _inode
+{
+    return shift->_stat_ret->[1];
+}
+
 sub _reset_actions
 {
     my $self = shift;
     );
 }
 
-sub _mystat
-{
-    my $self = shift;
-
-    my @st = stat($self->_dir_as_string());
-    $self->_inode($st[1]);
-    $self->_dev($st[0]);
-
-    return;
-}
-
 sub _should_scan_dir
 {
     my $self = shift;
 
     $self->_traverse_to($self->_files_copy());
     
-    $self->_mystat();
-
     return $self->_open_dir_ret(1);
 }