Skip to content

Commit d54c252

Browse files
committed
[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
1 parent f902a7e commit d54c252

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

llvm/lib/Option/OptTable.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,9 @@ static unsigned matchOption(const OptTable::Info *I, StringRef Str,
198198
static bool optionMatches(const OptTable::Info &In, StringRef Option) {
199199
if (In.Prefixes)
200200
for (size_t I = 0; In.Prefixes[I]; I++)
201-
if (Option == std::string(In.Prefixes[I]) + In.Name)
202-
return true;
201+
if (Option.endswith(In.Name))
202+
if (Option == std::string(In.Prefixes[I]) + In.Name)
203+
return true;
203204
return false;
204205
}
205206

0 commit comments

Comments
 (0)