Commits

Anonymous committed 47df5ca

Optimization: eliminated the _top_it() call.

  • Participants
  • Parent commits ba04b42

Comments (0)

Files changed (3)

     - 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.
+    - Optimization: replaced the _top_it() of _me_die() with a normal method
+    with a conditional, as it was the only place where _top_it() was still
+    used.
 
 0.1.8 - Mon Jan 19 18:36:51 IST 2009
     - Optimization/Refactoring: replaced the last call to ->_father with a 

lib/File/Find/Object.pm

     }
     ;
 
-# This is a variation of the Conditional-to-Inheritance refactoring - 
-# we have two methods - one if _is_top is true
-# and the other if it's false.
-#
-# This has been a common pattern in the code and should be eliminated.
-#
-# _d is the deep method.
-# and _t is the top one.
-
-sub _top_it
-{
-    my ($pkg, $methods) = @_;
-
-    no strict 'refs';
-    foreach my $method (@$methods)
-    {
-        *{$pkg."::".$method} =
-            do {
-                my $m = $method;
-                my $t = $m . "_t";
-                my $d = $m . "_d";
-                sub {
-                    my $self = shift;
-                    return exists($self->{_st})
-                        ? $self->$d(@_)
-                        : $self->$t(@_)
-                        ;
-                };
-            };
-    }
-
-    return;
-}
-
-__PACKAGE__->_top_it([qw(
-    _me_die
-    )]
-);
-
 __PACKAGE__->_make_copy_methods([qw(
     _top_stat
     )]
 sub new {
     my ($class, $options, @targets) = @_;
 
-    # The *existence* of a _st key inside the struct
+    # The *existence* of an _st key inside the struct
     # indicates that the stack is full.
     # So now it's empty.
     my $tree = {
     return $self->_current()->_move_next($self);
 }
 
-sub _me_die_t {
-    shift->item_obj(undef());
-
-    return 1;
-}
-
-sub _me_die_d {
+sub _me_die {
     my $self = shift;
 
-    return $self->_become_default();
+    if (exists($self->{_st})) {
+        return $self->_become_default();
+    }
+
+    $self->item_obj(undef());
+    return 1;
 }
 
 sub _become_default

rejects/File/Find/Object.pm

      ;
 }
 
+# This is a variation of the Conditional-to-Inheritance refactoring - 
+# we have two methods - one if _is_top is true
+# and the other if it's false.
+#
+# This has been a common pattern in the code and should be eliminated.
+#
+# _d is the deep method.
+# and _t is the top one.
+
+sub _top_it
+{
+    my ($pkg, $methods) = @_;
+
+    no strict 'refs';
+    foreach my $method (@$methods)
+    {
+        *{$pkg."::".$method} =
+            do {
+                my $m = $method;
+                my $t = $m . "_t";
+                my $d = $m . "_d";
+                sub {
+                    my $self = shift;
+                    return exists($self->{_st})
+                        ? $self->$d(@_)
+                        : $self->$t(@_)
+                        ;
+                };
+            };
+    }
+
+    return;
+}
+
+__PACKAGE__->_top_it([qw(
+    _me_die
+    )]
+);
+