[Support] Rewrite GlobPattern
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
Please sign in to comment