Skip to content

Minor performance nit: overuse of regex for simple string comparisons #318

@grr

Description

@grr

I was looking through the source and noticed there are many instances in the code where a regex is used for relatively simple strings checks. Something like $other->[PATH] =~ m{^\Q$self->[PATH]\E} would be faster with: ! rindex $other->[PATH], $self->[PATH], 0. And something like $new_mode =~ /[=+-]/ should be $newmode =~ tr/=+-//. Even some of the substitution regex are minor enough to use substr.

Tiny code doesn't necessitate slower code.

P.S. I noticed this bit in relative which does unecessary work when $base->is_rootdir:

 $base = "" if $base->is_rootdir;
 my $relative = "$self";
 $relative =~ s{\A\Q$base/}{};

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions