switch AddLineNumber to use a SmallString instead of sstream. This

speeds up -emit-html on ted's testcase by 29% (.138 -> 0.107s) in a
release build.

llvm-svn: 49767
This commit is contained in:
Chris Lattner 2008-04-16 04:11:35 +00:00
parent 08623f21ae
commit 05e5310ad8
1 changed files with 12 additions and 10 deletions

View File

@ -15,6 +15,7 @@
#include "clang/Rewrite/Rewriter.h"
#include "clang/Rewrite/HTMLRewrite.h"
#include "clang/Basic/SourceManager.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/Support/MemoryBuffer.h"
#include <sstream>
@ -113,17 +114,18 @@ std::string html::EscapeText(const std::string& s, bool EscapeSpaces,
static void AddLineNumber(Rewriter& R, unsigned LineNo,
SourceLocation B, SourceLocation E) {
std::ostringstream os;
os << "<tr><td class=\"num\" id=\"LN" << LineNo << "\">"
<< LineNo << "</td><td class=\"line\">";
llvm::SmallString<100> Str;
Str += "<tr><td class=\"num\" id=\"LN";
Str.append_uint(LineNo);
Str += "\">";
Str.append_uint(LineNo);
Str += "</td><td class=\"line\">";
if (B == E) { // Handle empty lines.
os << " </td></tr>";
R.InsertStrBefore(B, os.str());
}
else {
R.InsertStrBefore(B, os.str());
Str += " </td></tr>";
R.InsertTextBefore(B, &Str[0], Str.size());
} else {
R.InsertTextBefore(B, &Str[0], Str.size());
R.InsertCStrBefore(E, "</td></tr>");
}
}