forked from llvm/llvm-project
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The current implementation has two primary issues: * Matching `a*a*a*b` against `aaaaaa` has exponential complexity. * BitVector harms data cache and is inefficient for literal matching. and a minor issue that `\` at the end may cause an out of bounds access in `StringRef::operator[]`. Switch to an O(|S|*|P|) greedy algorithm instead: factor the pattern into segments split by '*'. The segment is matched sequentianlly by finding the first occurrence past the end of the previous match. This algorithm is used by lots of fnmatch implementations, including musl and NetBSD's. In addition, `optional<StringRef> Exact, Suffix, Prefix` wastes space. Instead, match the non-metacharacter prefix against the haystack, then match the pattern with the rest. In practice `*suffix` style patterns are less common and our new algorithm is fast enough, so don't bother storing the non-metacharacter suffix. Note: brace expansions (D153587) can leverage the `matchOne` function. Differential Revision: https://reviews.llvm.org/D156046
- Loading branch information
Showing
3 changed files
with
100 additions
and
125 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters