Avoid std::string thrashing in MultiKeywordSelector::getName(), and simplify.

llvm-svn: 84343
This commit is contained in:
Daniel Dunbar 2009-10-17 18:13:02 +00:00
parent acb5a4b57c
commit 1c0761d6e9
1 changed files with 12 additions and 19 deletions

View File

@ -16,6 +16,7 @@
#include "clang/Basic/LangOptions.h" #include "clang/Basic/LangOptions.h"
#include "llvm/ADT/FoldingSet.h" #include "llvm/ADT/FoldingSet.h"
#include "llvm/ADT/DenseMap.h" #include "llvm/ADT/DenseMap.h"
#include "llvm/Support/raw_ostream.h"
#include <cstdio> #include <cstdio>
using namespace clang; using namespace clang;
@ -153,7 +154,7 @@ tok::PPKeywordKind IdentifierInfo::getPPKeywordID() const {
unsigned Len = getLength(); unsigned Len = getLength();
if (Len < 2) return tok::pp_not_keyword; if (Len < 2) return tok::pp_not_keyword;
const char *Name = getName(); const char *Name = getNameStart();
switch (HASH(Len, Name[0], Name[2])) { switch (HASH(Len, Name[0], Name[2])) {
default: return tok::pp_not_keyword; default: return tok::pp_not_keyword;
CASE( 2, 'i', '\0', if); CASE( 2, 'i', '\0', if);
@ -301,24 +302,15 @@ IdentifierInfo *Selector::getIdentifierInfoForSlot(unsigned argIndex) const {
} }
std::string MultiKeywordSelector::getName() const { std::string MultiKeywordSelector::getName() const {
std::string Result; llvm::SmallString<256> Str;
unsigned Length = 0; llvm::raw_svector_ostream OS(Str);
for (keyword_iterator I = keyword_begin(), E = keyword_end(); I != E; ++I) { for (keyword_iterator I = keyword_begin(), E = keyword_end(); I != E; ++I) {
if (*I) if (*I)
Length += (*I)->getLength(); OS << (*I)->getNameStr();
++Length; // : OS << ':';
} }
Result.reserve(Length); return OS.str();
for (keyword_iterator I = keyword_begin(), E = keyword_end(); I != E; ++I) {
if (*I)
Result.insert(Result.end(), (*I)->getName(),
(*I)->getName()+(*I)->getLength());
Result.push_back(':');
}
return Result;
} }
std::string Selector::getAsString() const { std::string Selector::getAsString() const {
@ -330,11 +322,12 @@ std::string Selector::getAsString() const {
// If the number of arguments is 0 then II is guaranteed to not be null. // If the number of arguments is 0 then II is guaranteed to not be null.
if (getNumArgs() == 0) if (getNumArgs() == 0)
return II->getName(); return II->getNameStr();
std::string Res = II ? II->getName() : ""; if (!II)
Res += ":"; return ":";
return Res;
return II->getNameStr().str() + ":";
} }
// We have a multiple keyword selector (no embedded flags). // We have a multiple keyword selector (no embedded flags).