summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2005-11-10 21:47:01 +0000
committerChris Lattner <sabre@nondot.org>2005-11-10 21:47:01 +0000
commit86164e6e9eb537be364f5601392fbbf316d9a30a (patch)
tree3ffdd393e51ddee120a366bcb097d5440f7b805e /llvm/lib
parente1d34bac0b96253789b98aa787ea2147eb2ea229 (diff)
downloadbcm5719-llvm-86164e6e9eb537be364f5601392fbbf316d9a30a.tar.gz
bcm5719-llvm-86164e6e9eb537be364f5601392fbbf316d9a30a.zip
speedup the common case where nothing needs to be quoted
llvm-svn: 24294
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/VMCore/Mangler.cpp27
1 files changed, 20 insertions, 7 deletions
diff --git a/llvm/lib/VMCore/Mangler.cpp b/llvm/lib/VMCore/Mangler.cpp
index 44fe1003140..264b84c6fe3 100644
--- a/llvm/lib/VMCore/Mangler.cpp
+++ b/llvm/lib/VMCore/Mangler.cpp
@@ -65,16 +65,29 @@ std::string Mangler::makeNameProper(const std::string &X, const char *Prefix) {
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;
}
OpenPOWER on IntegriCloud