1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-18 18:42:46 +02:00

[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
This commit is contained in:
Nadav Rotem 2020-08-12 22:47:53 -07:00
parent 11fc43fd2a
commit 5c8e661d88

View File

@ -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;
}