diff options
author | Reid Kleckner <reid@kleckner.net> | 2013-07-15 13:46:24 +0000 |
---|---|---|
committer | Reid Kleckner <reid@kleckner.net> | 2013-07-15 13:46:24 +0000 |
commit | cacb40c6c7277f85bdfe1f601f4b45fd93cebeef (patch) | |
tree | 1167a6295ce8fae549500af16e8b8e95b3f54969 /llvm/lib/Option/ArgList.cpp | |
parent | d0d27ab306f47045efad43f1964d7ef7e0d92ac0 (diff) | |
download | bcm5719-llvm-cacb40c6c7277f85bdfe1f601f4b45fd93cebeef.tar.gz bcm5719-llvm-cacb40c6c7277f85bdfe1f601f4b45fd93cebeef.zip |
[Option] Store arg strings in a set backed by a BumpPtrAllocator
No functionality change.
This is preparing to move response file parsing into lib/Option so it
can be shared between clang and lld. This change isn't just a
micro-optimization. Clang's driver uses a std::set<std::string> to
unique arguments while parsing response files, so this matches that.
llvm-svn: 186319
Diffstat (limited to 'llvm/lib/Option/ArgList.cpp')
-rw-r--r-- | llvm/lib/Option/ArgList.cpp | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/llvm/lib/Option/ArgList.cpp b/llvm/lib/Option/ArgList.cpp index 15f7e8bf4b8..18a7b5982be 100644 --- a/llvm/lib/Option/ArgList.cpp +++ b/llvm/lib/Option/ArgList.cpp @@ -323,9 +323,18 @@ InputArgList::~InputArgList() { unsigned InputArgList::MakeIndex(StringRef String0) const { unsigned Index = ArgStrings.size(); + // If necessary, make a copy so we can null terminate it. + std::string NullTerminated; + if (String0.back() != '\0') { + NullTerminated.append(String0.data(), String0.size()); + NullTerminated.push_back('\0'); + String0 = StringRef(&NullTerminated[0], NullTerminated.size()); + } + // Tuck away so we have a reliable const char *. - SynthesizedStrings.push_back(String0); - ArgStrings.push_back(SynthesizedStrings.back().c_str()); + String0 = SynthesizedStrings.GetOrCreateValue(String0).getKey(); + assert(String0.back() == '\0'); + ArgStrings.push_back(String0.data()); return Index; } |