Pass in a std::string when getting the names of debugging things. This cuts down
on the number of times a std::string is created and copied.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@66396 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Analysis/DebugInfo.cpp b/lib/Analysis/DebugInfo.cpp
index a063aa5..4e229e9 100644
--- a/lib/Analysis/DebugInfo.cpp
+++ b/lib/Analysis/DebugInfo.cpp
@@ -35,17 +35,23 @@
     GV = 0;
 }
 
+const std::string &
+DIDescriptor::getStringField(unsigned Elt, std::string &Result) const {
+  if (GV == 0) {
+    Result.clear();
+    return Result;
+  }
 
-std::string DIDescriptor::getStringField(unsigned Elt) const {
-  if (GV == 0) return "";
   Constant *C = GV->getInitializer();
-  if (C == 0 || Elt >= C->getNumOperands())
-    return "";
+  if (C == 0 || Elt >= C->getNumOperands()) {
+    Result.clear();
+    return Result;
+  }
   
-  std::string Result;
   // Fills in the string if it succeeds
   if (!GetConstantStringInfo(C->getOperand(Elt), Result))
     Result.clear();
+
   return Result;
 }
 
@@ -59,7 +65,6 @@
   return 0;
 }
 
-
 DIDescriptor DIDescriptor::getDescriptorField(unsigned Elt) const {
   if (GV == 0) return DIDescriptor();
   Constant *C = GV->getInitializer();
@@ -185,7 +190,8 @@
 bool DICompileUnit::Verify() const {
   if (isNull()) 
     return false;
-  if (getFilename().empty()) 
+  std::string Res;
+  if (getFilename(Res).empty()) 
     return false;
   // It is possible that directory and produce string is empty.
   return true;
@@ -864,16 +870,22 @@
 void DICompileUnit::dump() const {
   if (getLanguage())
     cerr << " [" << dwarf::LanguageString(getLanguage()) << "] ";
-  cerr << " [" << getDirectory() << "/" << getFilename() << " ]";
+
+  std::string Res1, Res2;
+  cerr << " [" << getDirectory(Res1) << "/" << getFilename(Res2) << " ]";
 }
 
 /// dump - print type.
 void DIType::dump() const {
   if (isNull()) return;
-  if (!getName().empty())
-    cerr << " [" << getName() << "] ";
+
+  std::string Res;
+  if (!getName(Res).empty())
+    cerr << " [" << Res << "] ";
+
   unsigned Tag = getTag();
   cerr << " [" << dwarf::TagString(Tag) << "] ";
+
   // TODO : Print context
   getCompileUnit().dump();
   cerr << " [" 
@@ -882,10 +894,12 @@
        << getAlignInBits() << ", "
        << getOffsetInBits() 
        << "] ";
+
   if (isPrivate()) 
     cerr << " [private] ";
   else if (isProtected())
     cerr << " [protected] ";
+
   if (isForwardDecl())
     cerr << " [fwd] ";
 
@@ -899,6 +913,7 @@
     cerr << "Invalid DIType\n";
     return;
   }
+
   cerr << "\n";
 }
 
@@ -923,16 +938,20 @@
 
 /// dump - print global.
 void DIGlobal::dump() const {
+  std::string Res;
+  if (!getName(Res).empty())
+    cerr << " [" << Res << "] ";
 
-  if (!getName().empty())
-    cerr << " [" << getName() << "] ";
   unsigned Tag = getTag();
   cerr << " [" << dwarf::TagString(Tag) << "] ";
+
   // TODO : Print context
   getCompileUnit().dump();
   cerr << " [" << getLineNumber() << "] ";
+
   if (isLocalToUnit())
     cerr << " [local] ";
+
   if (isDefinition())
     cerr << " [def] ";
 
@@ -954,8 +973,10 @@
 
 /// dump - print variable.
 void DIVariable::dump() const {
-  if (!getName().empty())
-    cerr << " [" << getName() << "] ";
+  std::string Res;
+  if (!getName(Res).empty())
+    cerr << " [" << Res << "] ";
+
   getCompileUnit().dump();
   cerr << " [" << getLineNumber() << "] ";
   getType().dump();