Commits

shl...@6f433eb9-a002-0410-945b-ee5462c261ee  committed 5ec7dba

Converte to Class::XSAccessor instead of Class::Accessor.

This was done in hope of optimising F-F-O.

  • Participants
  • Parent commits 13289a6
  • Branches experimental-optimizations-1

Comments (0)

Files changed (6)

     'module_name' => "File::Find::Object",
     'requires' =>
     {
-        'Class::Accessor' => 0,
+        'Class::XSAccessor' => 0,
     },
     'license' => "perl",
 );
+    - Converted the accessor generator to Class::XSAccessor instead
+    of Class::Accessor. After consulting Devel::NYTProf, it seemed that
+    the majority of the time of a simple File-Find-Object scan was spent
+    in Class::Accessor. Hopefully, this will make F-F-O run faster.
+
 0.1.5 - Sat Jan  3 17:17:31 IST 2009
     - Unified the two calls to stat() (and several calls to other file
     operators) in order to reduce the number of system calls/disk accesses
     VERSION_FROM => 'lib/File/Find/Object.pm',
     PREREQ_PM =>
     {
-        'Class::Accessor' => 0,
+        'Class::XSAccessor' => 0,
     },
     PL_FILES => {},
 );

File lib/File/Find/Object.pm

 
 use File::Spec;
 
-
 sub new {
     my ($class, $top, $from, $index) = @_;
 
 
 use Fcntl ':mode';
 
-__PACKAGE__->mk_accessors(qw(
-    _dir_stack
-    item_obj
-    _targets
-    _target_index
-    _top_stat
-));
-
 sub _get_options_ids
 {
     my $class = shift;
     )];
 }
 
-__PACKAGE__->mk_accessors(@{__PACKAGE__->_get_options_ids()});
+use Class::XSAccessor
+    accessors => {
+        (map { $_ => $_ } 
+        (qw(
+            _dir_stack
+            item_obj
+            _targets
+            _target_index
+            _top_stat
+            ), 
+            @{__PACKAGE__->_get_options_ids()}
+        )
+        )
+    }
+    ;
 
 # This is a variation of the Conditional-to-Inheritance refactoring - 
 # we have two methods - one if _is_top is true
 
     foreach my $opt (@{$tree->_get_options_ids()})
     {
-        $tree->set($opt, $options->{$opt});
+        $tree->$opt($options->{$opt});
     }
     $tree->_targets(\@targets);
     $tree->_target_index(-1);

File lib/File/Find/Object/Base.pm

 use strict;
 use warnings;
 
-use base 'Class::Accessor';
+use Class::XSAccessor
+	accessors => {
+        (map
+            { $_ => $_ }
+            (qw(
+                _actions
+                _curr_file
+                _dir
+                _files
+                idx
+                _last_dir_scanned
+                _open_dir_ret
+                _stat_ret
+                _traverse_to
+            ))
+        ) 
+    }
+    ;
 
 use File::Spec;
 
-__PACKAGE__->mk_accessors(qw(
-    _actions
-    _curr_file
-    _dir
-    _files
-    idx
-    _last_dir_scanned
-    _open_dir_ret
-    _stat_ret
-    _traverse_to
-));
-
 # Create a _copy method that does a flat copy of an array returned by
 # a method as a reference.
 
 
 File::Find::Object::Base - base class for File::Find::Object
 
-=head2 DESCRIPTION
+=head1 DESCRIPTION
 
 This is the base class for F::F::O classes. It only defines some accessors,
 and is for File::Find::Object's internal use.
 
+=head1 METHODS
+
+=head2 $self->idx()
+
+For internal use.
+
 =head1 SEE ALSO
 
 L<File::Find::Object>

File lib/File/Find/Object/Result.pm

 use strict;
 use warnings;
 
-use base 'Class::Accessor';
+use Class::XSAccessor
+    accessors => {
+        (map { $_ => $_ } (qw(
+        base
+        basename
+        path
+        dir_components
+        stat_ret
+        )))
+    }
+    ;
 
 use Fcntl qw(:mode);
 
-__PACKAGE__->mk_accessors(qw(
-    base
-    basename
-    path
-    dir_components
-    stat_ret
-));
+sub new
+{
+    my $class = shift;
+    my $self = shift;
+
+    bless $self, $class;
+
+    return $self;
+}
 
 sub is_dir
 {
 
 =head1 METHODS
 
+=head2 File::Find::Object::Result->new({%args});
+
+Initializes a new object from %args. For internal use.
+
 =head2 $result->base()
 
 Returns the base directory from which searching began.