Anonymous avatar Anonymous committed 9d4e702

Optimization: handling callback() better in case it doesn't exist.

Comments (0)

Files changed (2)

-0.1.8 - Tue Feb 10 16:54:00 IST 2009
+    - Optimization: now not checking for the existence of the callback() after 
+    every iteration, in case it doesn't exist. Instead, the default_actions
+    is calculated according to its existence when the tree traverser
+    is initialized.
+    
+0.1.9 - Tue Feb 10 16:54:00 IST 2009
     - 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.

lib/File/Find/Object.pm

 sub _calc_default_actions {
     my $self = shift;
 
-    my @actions = qw(_handle_callback _recurse);
+    my @calc_obj =
+        $self->callback()
+        ? (qw(_set_obj_skip _run_cb))
+        : (qw(_set_obj))
+        ;
+
+    my @rec = qw(_recurse);
 
     $self->_def_actions(
-        [($self->depth() ? reverse(@actions) : @actions)]
+        [$self->depth()
+            ? (@rec, @calc_obj)
+            : (@calc_obj, @rec)
+        ]
     );
 
     return;
     }
 }
 
-sub _handle_callback {
+sub _set_obj {
     my $self = shift;
 
-    # Calculate next_obj now so it will be ready for the callback.
     $self->item_obj($self->_calc_current_item_obj());
 
-    if ($self->callback()) {
-        $self->callback()->($self->_curr_path());
-    }
+    return 1;
+}
+
+sub _set_obj_skip {
+    my $self = shift;
+
+    $self->item_obj($self->_calc_current_item_obj());
+
+    return "SKIP";
+}
+
+sub _run_cb {
+    my $self = shift;
+
+    $self->callback()->($self->_curr_path());
 
     return 1;
 }
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.