[llvm-commits] [llvm] r79437 - /llvm/trunk/lib/Support/Twine.cpp
Daniel Dunbar
daniel at zuster.org
Wed Aug 19 11:09:48 PDT 2009
Author: ddunbar
Date: Wed Aug 19 13:09:47 2009
New Revision: 79437
URL: http://llvm.org/viewvc/llvm-project?rev=79437&view=rev
Log:
Switch Twine::str() to use toVector(), which is now efficient.
Modified:
llvm/trunk/lib/Support/Twine.cpp
Modified: llvm/trunk/lib/Support/Twine.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Twine.cpp?rev=79437&r1=79436&r2=79437&view=diff
==============================================================================
--- llvm/trunk/lib/Support/Twine.cpp (original)
+++ llvm/trunk/lib/Support/Twine.cpp Wed Aug 19 13:09:47 2009
@@ -8,27 +8,17 @@
//===----------------------------------------------------------------------===//
#include "llvm/ADT/Twine.h"
+#include "llvm/ADT/SmallString.h"
#include "llvm/Support/raw_ostream.h"
using namespace llvm;
std::string Twine::str() const {
- // FIXME: This should probably use the toVector implementation, once that is
- // efficient.
- std::string Res;
- raw_string_ostream OS(Res);
- print(OS);
- OS.flush();
- return Res;
+ SmallString<256> Vec;
+ toVector(Vec);
+ return std::string(Vec.begin(), Vec.end());
}
void Twine::toVector(SmallVectorImpl<char> &Out) const {
- // FIXME: This is very inefficient, since we are creating a large raw_ostream
- // buffer -- hitting malloc, which we were supposed to avoid -- all when we
- // have this pretty little small vector available.
- //
- // The best way to fix this is to make raw_svector_ostream do the right thing
- // and be efficient, by augmenting the base raw_ostream with the ability to
- // have the buffer managed by a concrete implementation.
raw_svector_ostream OS(Out);
print(OS);
}
More information about the llvm-commits
mailing list