Commits

Anonymous committed 10f7ffd

Now compiling _check_subdir_helper() by eval ""'ing it.

  • Participants
  • Parent commits 0f9fbe8

Comments (0)

Files changed (2)

     and removed an unused one.
     - Refactoring: refactored _check_subdir_helper_d() to make
     the conditions clearer.
+    - Optimization: now compiling the _check_subdir_helper function
+    by eval ""'ing it because it contains many conditions that depend
+    on instance-wide and constant parameters. 
 
 0.1.7 - Thu Jan 15 16:09:49 IST 2009
     - Fixed the check-for-link and for directory semantics on Windows

lib/File/Find/Object.pm

     accessors => {
         (map { $_ => $_ } 
         (qw(
+            _check_subdir_h
             _curr_comps
             _current
             _curr_path
 }
 
 __PACKAGE__->_top_it([qw(
-    _check_subdir_helper
     _me_die
     )]
 );
         $tree->$opt($options->{$opt});
     }
 
+    $tree->_gen_check_subdir_helper();
+
     $tree->_targets(\@targets);
     $tree->_target_index(-1);
 
     }
     else
     {
-        return $self->_check_subdir_helper();
+        return $self->_check_subdir_h()->($self);
     }
 }
 
-sub _check_subdir_helper_t {
-    return 1;
-}
 
 
 sub _warn_about_loop
     }
 }
 
+=begin Removed
+
+This code was removed to be replaced with the eval ""-ed code.
+
+sub _check_subdir_helper_t {
+    return 1;
+}
+
 sub _check_subdir_helper_d {
     my $self = shift;
 
      ;
 }
 
+=end Removed
+
+=cut
+
+# We eval "" the helper of check_subdir because the conditions that
+# affect the checks are instance-wide and constant and so we can
+# determine how the code should look like.
+
+sub _gen_check_subdir_helper {
+    my $self = shift;
+
+    my @clauses;
+
+    if (!$self->followlink()) {
+        push @clauses, '$s->_top_is_link()';
+    }
+    
+    if ($self->nocrossfs()) {
+        push @clauses, '($s->_top_stat->[0] != $s->dev())';
+    }
+
+    push @clauses, '$s->_is_loop()';
+
+    $self->_check_subdir_h(
+        _context_less_eval(
+          'sub { my $s = shift; ' 
+        . 'return ((!exists($s->{_st})) || !('
+        . join("||", @clauses) . '));'
+        . '}'
+        )
+    );
+}
+
+sub _context_less_eval {
+    my $code = shift;
+    return eval $code;
+}
+
 sub _open_dir {
     my $self = shift;