Browse Source

- improved performance a little bit using look-behind in regex

- improved performance a little bit using look-ahead in regex
master
parent
commit
81beddc61c
1 changed files with 11 additions and 6 deletions
  1. +11
    -6
      lib/File/FormatIdentification/Pronom.pm

+ 11
- 6
lib/File/FormatIdentification/Pronom.pm View File

@@ -106,10 +106,10 @@ sub _flatten_rx ($@) {

# expands pattern of form "FFFB[10:EB]" to FFFB10, FFFB11, ... FFFBEB
sub _expand_pattern ($) {
my $pattern = shift;
$pattern =~ s/\[!/[^/g;
$pattern =~ s/([0-9A-F]{2}):([0-9A-F]{2})\]/$1-$2]/g;
$pattern =~ s/([0-9A-F]{2})/\\x$1/g;
my $pattern = $_[0];
$pattern =~ s/(?<=\[)!/^/g;
$pattern =~ s/(?<=[0-9A-F]{2}):(?=[0-9A-F]{2})\]/-]/g;
$pattern =~ s/(?=[0-9A-F]{2})/\\x/g;

# substitute hex with printable ASCII-Output
$pattern =~ s#\\x(3[0-9]|[46][1-9A-F]|[57][0-9A])#chr( hex($1) );#egs;
@@ -515,6 +515,7 @@ sub save_as_yamlfile {
push @res, $self->{signatures};
push @res, $self->{internal_signatures};
YAML::XS::DumpFile( "$filename", @res );
return;
} ## end sub save_as_yamlfile

sub load_from_yamlfile {
@@ -523,6 +524,7 @@ sub load_from_yamlfile {
my ( $sig, $int ) = YAML::XS::LoadFile($filename);
$self->{signatures} = $sig;
$self->{internal_signatures} = $int;
return;
} ## end sub load_from_yamlfile

has 'auto_store' => (
@@ -862,6 +864,7 @@ sub print_csv_statistics {
} @headers
);
close ($FH);
return;
}

sub print_statistics {
@@ -940,12 +943,14 @@ sub print_statistics {
#my @rx = $self->get_all_regular_expressions();
#use Data::Printer;
#p( %uniq_regexes );
return;
}

1;

no Moose;
__PACKAGE__->meta->make_immutable;
1;

__END__
# Below is stub documentation for your module. You'd better edit it!
@@ -988,11 +993,11 @@ If you have a web site set up for your module, mention it here.

=head1 AUTHOR

art1, E<lt>art1@E<gt>
art1

=head1 COPYRIGHT AND LICENSE

Copyright (C) 2018 by art1
Copyright (C) 2018/19 by art1

This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself, either Perl version 5.24.1 or,

Loading…
Cancel
Save