summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Support/raw_ostream.cpp
diff options
context:
space:
mode:
authorDaniel Dunbar <daniel@zuster.org>2009-03-16 22:08:44 +0000
committerDaniel Dunbar <daniel@zuster.org>2009-03-16 22:08:44 +0000
commit8786218b0ce977739bd74ff8d0a69aff8668e9db (patch)
tree7f25115f5ed631a03996aebb9e4fbed97915882a /llvm/lib/Support/raw_ostream.cpp
parent7a9bb9eeecae6752fb64c090c0d58c817e9cf499 (diff)
downloadbcm5719-llvm-8786218b0ce977739bd74ff8d0a69aff8668e9db.tar.gz
bcm5719-llvm-8786218b0ce977739bd74ff8d0a69aff8668e9db.zip
Make raw_ostream::operator<<(const void *) fast; it doesn't matter but
it is easy. llvm-svn: 67054
Diffstat (limited to 'llvm/lib/Support/raw_ostream.cpp')
-rw-r--r--llvm/lib/Support/raw_ostream.cpp21
1 files changed, 19 insertions, 2 deletions
diff --git a/llvm/lib/Support/raw_ostream.cpp b/llvm/lib/Support/raw_ostream.cpp
index 43f46837d37..3c242424beb 100644
--- a/llvm/lib/Support/raw_ostream.cpp
+++ b/llvm/lib/Support/raw_ostream.cpp
@@ -96,8 +96,24 @@ raw_ostream &raw_ostream::operator<<(long long N) {
}
raw_ostream &raw_ostream::operator<<(const void *P) {
- // FIXME: This could be much faster if it matters.
- return *this << format("%p", P);
+ uintptr_t N = (uintptr_t) P;
+ *this << '0' << 'x';
+
+ // Zero is a special case.
+ if (N == 0)
+ return *this << '0';
+
+ char NumberBuffer[20];
+ char *EndPtr = NumberBuffer+sizeof(NumberBuffer);
+ char *CurPtr = EndPtr;
+
+ while (N) {
+ unsigned x = N % 16;
+ *--CurPtr = (x < 10 ? '0' + x : 'a' + x - 10);
+ N /= 16;
+ }
+
+ return write(CurPtr, EndPtr-CurPtr);
}
raw_ostream &raw_ostream::write(unsigned char C) {
@@ -105,6 +121,7 @@ raw_ostream &raw_ostream::write(unsigned char C) {
flush_impl();
*OutBufCur++ = C;
+ return *this;
}
raw_ostream &raw_ostream::write(const char *Ptr, unsigned Size) {
OpenPOWER on IntegriCloud