[PATCH] Avoid extra back reference key lookup in msmangler
Agustín Bergé
kaballo86 at hotmail.com
Tue Jun 24 11:54:15 PDT 2014
Changes in this iteration:
- Use the new `StringMap::insert` overload.
- Template instantiation names are source names, mangle them as such.
http://reviews.llvm.org/D4130
Files:
lib/AST/MicrosoftMangle.cpp
Index: lib/AST/MicrosoftMangle.cpp
===================================================================
--- lib/AST/MicrosoftMangle.cpp
+++ lib/AST/MicrosoftMangle.cpp
@@ -650,6 +650,7 @@
// FIXME: Test alias template mangling with MSVC 2013.
if (!isa<ClassTemplateDecl>(TD)) {
mangleTemplateInstantiationName(TD, *TemplateArgs);
+ Out << '@';
return;
}
@@ -668,22 +669,13 @@
// the mangled type name as a key to check the mangling of different types
// for aliasing.
- std::string TemplateMangling;
- llvm::raw_string_ostream Stream(TemplateMangling);
+ llvm::SmallString<64> TemplateMangling;
+ llvm::raw_svector_ostream Stream(TemplateMangling);
MicrosoftCXXNameMangler Extra(Context, Stream);
Extra.mangleTemplateInstantiationName(TD, *TemplateArgs);
Stream.flush();
- BackRefMap::iterator Found = NameBackReferences.find(TemplateMangling);
- if (Found == NameBackReferences.end()) {
- Out << TemplateMangling;
- if (NameBackReferences.size() < 10) {
- size_t Size = NameBackReferences.size();
- NameBackReferences[TemplateMangling] = Size;
- }
- } else {
- Out << Found->second;
- }
+ mangleSourceName(TemplateMangling);
return;
}
@@ -1002,13 +994,20 @@
void MicrosoftCXXNameMangler::mangleSourceName(StringRef Name) {
// <source name> ::= <identifier> @
- BackRefMap::iterator Found = NameBackReferences.find(Name);
+ BackRefMap::iterator Found;
+ if (NameBackReferences.size() < 10) {
+ size_t Size = NameBackReferences.size();
+ bool Inserted;
+ std::tie(Found, Inserted) =
+ NameBackReferences.insert(std::make_pair(Name, Size));
+ if (Inserted)
+ Found = NameBackReferences.end();
+ } else {
+ Found = NameBackReferences.find(Name);
+ }
+
if (Found == NameBackReferences.end()) {
Out << Name << '@';
- if (NameBackReferences.size() < 10) {
- size_t Size = NameBackReferences.size();
- NameBackReferences[Name] = Size;
- }
} else {
Out << Found->second;
}
@@ -1104,10 +1103,9 @@
void MicrosoftCXXNameMangler::mangleTemplateArgs(
const TemplateDecl *TD, const TemplateArgumentList &TemplateArgs) {
- // <template-args> ::= <template-arg>+ @
+ // <template-args> ::= <template-arg>+
for (const TemplateArgument &TA : TemplateArgs.asArray())
mangleTemplateArg(TD, TA);
- Out << '@';
}
void MicrosoftCXXNameMangler::mangleTemplateArg(const TemplateDecl *TD,
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D4130.10800.patch
Type: text/x-patch
Size: 2562 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140624/1debec9b/attachment.bin>
More information about the cfe-commits
mailing list