[llvm-commits] CVS: llvm/lib/VMCore/Mangler.cpp

Chris Lattner lattner at cs.uiuc.edu
Thu Nov 10 13:47:13 PST 2005



Changes in directory llvm/lib/VMCore:

Mangler.cpp updated: 1.23 -> 1.24
---
Log message:

speedup the common case where nothing needs to be quoted


---
Diffs of the changes:  (+20 -7)

 Mangler.cpp |   27 ++++++++++++++++++++-------
 1 files changed, 20 insertions(+), 7 deletions(-)


Index: llvm/lib/VMCore/Mangler.cpp
diff -u llvm/lib/VMCore/Mangler.cpp:1.23 llvm/lib/VMCore/Mangler.cpp:1.24
--- llvm/lib/VMCore/Mangler.cpp:1.23	Thu Nov 10 15:40:01 2005
+++ llvm/lib/VMCore/Mangler.cpp	Thu Nov 10 15:47:01 2005
@@ -65,16 +65,29 @@
     if (*I >= '0' && *I <= '9')
       NeedsQuotes = true;
     
-    for (std::string::const_iterator E = X.end(); I != E; ++I)
+    // Do an initial scan of the string, checking to see if we need quotes or
+    // to escape a '"' or not.
+    if (!NeedsQuotes)
+      for (std::string::const_iterator E = X.end(); I != E; ++I)
+        if (!isCharAcceptable(*I)) {
+          NeedsQuotes = true;
+          break;
+        }
+    
+    // In the common case, we don't need quotes.  Handle this quickly.
+    if (!NeedsQuotes)
+      return Result + X;
+    
+    // Otherwise, construct the string the expensive way.
+    I = X.begin();
+    if (*I == 1) ++I;   // Skip the marker if present.
+    for (std::string::const_iterator E = X.end(); I != E; ++I) {
       if (*I == '"')
         Result += "_QQ_";
-      else {
-        if (!isCharAcceptable(*I))
-          NeedsQuotes = true;
+      else
         Result += *I;
-      }
-    if (NeedsQuotes)
-      Result = '"' + Result + '"';
+    }
+    Result = '"' + Result + '"';
   }
   return Result;
 }






More information about the llvm-commits mailing list