[llvm-commits] [llvm] r67054 - /llvm/trunk/lib/Support/raw_ostream.cpp
Daniel Dunbar
daniel at zuster.org
Mon Mar 16 15:08:44 PDT 2009
Author: ddunbar
Date: Mon Mar 16 17:08:44 2009
New Revision: 67054
URL: http://llvm.org/viewvc/llvm-project?rev=67054&view=rev
Log:
Make raw_ostream::operator<<(const void *) fast; it doesn't matter but
it is easy.
Modified:
llvm/trunk/lib/Support/raw_ostream.cpp
Modified: llvm/trunk/lib/Support/raw_ostream.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/raw_ostream.cpp?rev=67054&r1=67053&r2=67054&view=diff
==============================================================================
--- llvm/trunk/lib/Support/raw_ostream.cpp (original)
+++ llvm/trunk/lib/Support/raw_ostream.cpp Mon Mar 16 17:08:44 2009
@@ -96,8 +96,24 @@
}
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 @@
flush_impl();
*OutBufCur++ = C;
+ return *this;
}
raw_ostream &raw_ostream::write(const char *Ptr, unsigned Size) {
More information about the llvm-commits
mailing list