aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Option/OptTable.cpp
diff options
context:
space:
mode:
authorNadav Rotem <nadav256@gmail.com>2020-08-12 22:47:53 -0700
committerNadav Rotem <nadav256@gmail.com>2020-08-12 23:07:07 -0700
commitd54c252bc8a15bc80bb9f0a83b3bebc6d211144a (patch)
tree3e35f1ac7cd8a6e002821d6bd72ab94aca90e6c9 /llvm/lib/Option/OptTable.cpp
parentf902a7eccf30a762d9a533c3884edfb692c26a09 (diff)
downloadllvm-d54c252bc8a15bc80bb9f0a83b3bebc6d211144a.zip
llvm-d54c252bc8a15bc80bb9f0a83b3bebc6d211144a.tar.gz
llvm-d54c252bc8a15bc80bb9f0a83b3bebc6d211144a.tar.bz2
[Clang options] Optimize optionMatches() runtime by removing mallocs
The method optionMatches() constructs 9865 std::string instances when comparing different options. Many of these instances exceed the size of the internal storage and force memory allocations. This patch adds an early exit check that eliminates most of the string allocations while keeping the code simple. Example inputs: Prefix: /, Name: Fr Prefix: -, Name: Fr Prefix: -, Name: fsanitize-address-field-padding= Prefix: -, Name: fsanitize-address-globals-dead-stripping Prefix: -, Name: fsanitize-address-poison-custom-array-cookie Prefix: -, Name: fsanitize-address-use-after-scope Prefix: -, Name: fsanitize-address-use-odr-indicator Prefix: -, Name: fsanitize-blacklist= Differential Revision: D85538
Diffstat (limited to 'llvm/lib/Option/OptTable.cpp')
-rw-r--r--llvm/lib/Option/OptTable.cpp5
1 files changed, 3 insertions, 2 deletions
diff --git a/llvm/lib/Option/OptTable.cpp b/llvm/lib/Option/OptTable.cpp
index 2b7fcf5..740e02a 100644
--- a/llvm/lib/Option/OptTable.cpp
+++ b/llvm/lib/Option/OptTable.cpp
@@ -198,8 +198,9 @@ static unsigned matchOption(const OptTable::Info *I, StringRef Str,
static bool optionMatches(const OptTable::Info &In, StringRef Option) {
if (In.Prefixes)
for (size_t I = 0; In.Prefixes[I]; I++)
- if (Option == std::string(In.Prefixes[I]) + In.Name)
- return true;
+ if (Option.endswith(In.Name))
+ if (Option == std::string(In.Prefixes[I]) + In.Name)
+ return true;
return false;
}