diff options
author | Fangrui Song <i@maskray.me> | 2023-07-25 18:46:55 -0700 |
---|---|---|
committer | Fangrui Song <i@maskray.me> | 2023-07-25 18:46:55 -0700 |
commit | 4553dc46a05ec6f1e2aebcde1ce185772a26780b (patch) | |
tree | e8743148ed6c1c1cdc2fa60c7a7cf643bd490395 /llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp | |
parent | 16b2569f8e74f93070860b803efdc54367b3ed31 (diff) | |
download | llvm-4553dc46a05ec6f1e2aebcde1ce185772a26780b.zip llvm-4553dc46a05ec6f1e2aebcde1ce185772a26780b.tar.gz llvm-4553dc46a05ec6f1e2aebcde1ce185772a26780b.tar.bz2 |
[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
Diffstat (limited to 'llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp')
0 files changed, 0 insertions, 0 deletions