[lld] r193444 - [PECOFF] Do not create a temporary std::string.

Rui Ueyama ruiu at google.com
Fri Oct 25 15:31:57 PDT 2013


Author: ruiu
Date: Fri Oct 25 17:31:56 2013
New Revision: 193444

URL: http://llvm.org/viewvc/llvm-project?rev=193444&view=rev
Log:
[PECOFF] Do not create a temporary std::string.

Modified:
    lld/trunk/lib/Driver/WinLinkDriver.cpp

Modified: lld/trunk/lib/Driver/WinLinkDriver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Driver/WinLinkDriver.cpp?rev=193444&r1=193443&r2=193444&view=diff
==============================================================================
--- lld/trunk/lib/Driver/WinLinkDriver.cpp (original)
+++ lld/trunk/lib/Driver/WinLinkDriver.cpp Fri Oct 25 17:31:56 2013
@@ -248,28 +248,26 @@ std::string createManifestXml(PECOFFLink
 
 // Convert one doublequote to two doublequotes, so that we can embed the string
 // into a resource script file.
-std::string quoteXml(StringRef str) {
-  std::string ret;
-  ret.reserve(str.size() * 2);
-  StringRef line;
+void quoteAndPrintXml(raw_ostream &out, StringRef str) {
   for (;;) {
     if (str.empty())
-      return std::move(ret);
+      return;
+    StringRef line;
     llvm::tie(line, str) = str.split("\n");
     if (!line.empty())
       continue;
-    ret.append("\"");
+    out << '\"';
     const char *p = line.data();
     for (int i = 0, size = line.size(); i < size; ++i) {
       switch (p[i]) {
       case '\"':
-        ret.append("\"");
+        out << '\"';
         // fallthrough
       default:
-        ret.append(1, p[i]);
+        out << p[i];
       }
     }
-    ret.append("\"\n");
+    out << "\"\n";
   }
 }
 
@@ -309,9 +307,9 @@ bool createManifestResourceFile(PECOFFLi
       << "#define APP_MANIFEST " << ctx.getManifestId() << "\n"
       << "#define RT_MANIFEST 24\n"
       << "LANGUAGE LANG_ENGLISH, SUBLANG_DEFAULT\n"
-      << "APP_MANIFEST RT_MANIFEST {\n"
-      << quoteXml(createManifestXml(ctx))
-      << "}\n";
+      << "APP_MANIFEST RT_MANIFEST {\n";
+  quoteAndPrintXml(out, createManifestXml(ctx));
+  out << "}\n";
   out.close();
 
   // Create output resource file.





More information about the llvm-commits mailing list