goelhardik / ignore

.gitignore based parser implemented in C# according to the .gitignore spec 2.29.2.
MIT License
50 stars 5 forks source link

Support ReadOnlySpan<char> for IsMatch() #39

Open kjpgit opened 1 year ago

kjpgit commented 1 year ago

Example:

  public bool IsMatch(ReadOnlySpan<char> input)
    {
        return parsedRegex != null && parsedRegex.IsMatch(input);
    }

Just add that signature in addition to the one taking string.

This reduces my time of scanning 200K files from 1.79 --> 1.57 seconds.

It's because the ReadOnlySpan supports an efficient Slice() operation, so I'm not scanning the part of the path above where the .gitignore file resides.

I'm the author of ViLark, a file chooser for vim, sort of like fzf.

And thanks for this library, it helps a lot. Although I am getting very slow performance with a wildcard like '*.pyc', I might dig into that if I have time.

goelhardik commented 1 year ago

Thanks for the suggestion. Feel free to raise a PR, otherwise I will try to get to this tomorrow.

Yeah always good to improve performance. The library uses a bunch of regex, which I tried to follow best practices for, but maybe there can be improvements there.