llvm.org GIT mirror llvm / 66b17ba
Move non-trivial methods out of line to avoid code-size bloat. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@55138 91177308-0d34-0410-b5e6-96231b3b80d8 Owen Anderson 11 years ago
2 changed file(s) with 97 addition(s) and 87 deletion(s). Raw diff Collapse all Expand all
7676 return write(Str.data(), Str.length());
7777 }
7878
79 raw_ostream &operator<<(unsigned long N) {
80 // Zero is a special case.
81 if (N == 0)
82 return *this << '0';
83
84 char NumberBuffer[20];
85 char *EndPtr = NumberBuffer+sizeof(NumberBuffer);
86 char *CurPtr = EndPtr;
87
88 while (N) {
89 *--CurPtr = '0' + char(N % 10);
90 N /= 10;
91 }
92 return write(CurPtr, EndPtr-CurPtr);
93 }
79 raw_ostream &operator<<(unsigned long N);
9480
95 raw_ostream &operator<<(long N) {
96 if (N < 0) {
97 if (OutBufCur >= OutBufEnd)
98 flush_impl();
99 *OutBufCur++ = '-';
100
101 N = -N;
102 }
103
104 return this->operator<<(static_cast(N));
105 }
81 raw_ostream &operator<<(long N);
10682
107 raw_ostream &operator<<(unsigned long long N) {
108 // Zero is a special case.
109 if (N == 0)
110 return *this << '0';
111
112 char NumberBuffer[20];
113 char *EndPtr = NumberBuffer+sizeof(NumberBuffer);
114 char *CurPtr = EndPtr;
115
116 while (N) {
117 *--CurPtr = '0' + char(N % 10);
118 N /= 10;
119 }
120 return write(CurPtr, EndPtr-CurPtr);
121 }
83 raw_ostream &operator<<(unsigned long long N);
12284
123 raw_ostream &operator<<(long long N) {
124 if (N < 0) {
125 if (OutBufCur >= OutBufEnd)
126 flush_impl();
127 *OutBufCur++ = '-';
128
129 N = -N;
130 }
131
132 return this->operator<<(static_cast(N));
133 }
85 raw_ostream &operator<<(long long N);
13486
13587 raw_ostream &operator<<(unsigned int N) {
13688 return this->operator<<(static_cast(N));
14597 }
14698
14799
148 raw_ostream &write(const char *Ptr, unsigned Size) {
149 if (OutBufCur+Size > OutBufEnd)
150 flush_impl();
151
152 // Handle short strings specially, memcpy isn't very good at very short
153 // strings.
154 switch (Size) {
155 case 4: OutBufCur[3] = Ptr[3]; // FALL THROUGH
156 case 3: OutBufCur[2] = Ptr[2]; // FALL THROUGH
157 case 2: OutBufCur[1] = Ptr[1]; // FALL THROUGH
158 case 1: OutBufCur[0] = Ptr[0]; // FALL THROUGH
159 case 0: break;
160 default:
161 // Normally the string to emit is shorter than the buffer.
162 if (Size <= unsigned(OutBufEnd-OutBufStart)) {
163 memcpy(OutBufCur, Ptr, Size);
164 break;
165 }
166
167 // If emitting a string larger than our buffer, emit in chunks. In this
168 // case we know that we just flushed the buffer.
169 while (Size) {
170 unsigned NumToEmit = OutBufEnd-OutBufStart;
171 if (Size < NumToEmit) NumToEmit = Size;
172 assert(OutBufCur == OutBufStart);
173 memcpy(OutBufStart, Ptr, NumToEmit);
174 Ptr += NumToEmit;
175 OutBufCur = OutBufStart + NumToEmit;
176 flush_impl();
177 }
178 break;
179 }
180 OutBufCur += Size;
181 return *this;
182 }
100 raw_ostream &write(const char *Ptr, unsigned Size);
183101
184102 //===--------------------------------------------------------------------===//
185103 // Subclass Interface
3131
3232 // An out of line virtual method to provide a home for the class vtable.
3333 void raw_ostream::handle() {}
34
35 raw_ostream &raw_ostream::operator<<(unsigned long N) {
36 // Zero is a special case.
37 if (N == 0)
38 return *this << '0';
39
40 char NumberBuffer[20];
41 char *EndPtr = NumberBuffer+sizeof(NumberBuffer);
42 char *CurPtr = EndPtr;
43
44 while (N) {
45 *--CurPtr = '0' + char(N % 10);
46 N /= 10;
47 }
48 return write(CurPtr, EndPtr-CurPtr);
49 }
50
51 raw_ostream &raw_ostream::operator<<(long N) {
52 if (N < 0) {
53 if (OutBufCur >= OutBufEnd)
54 flush_impl();
55 *OutBufCur++ = '-';
56
57 N = -N;
58 }
59
60 return this->operator<<(static_cast(N));
61 }
62
63 raw_ostream &raw_ostream::operator<<(unsigned long long N) {
64 // Zero is a special case.
65 if (N == 0)
66 return *this << '0';
67
68 char NumberBuffer[20];
69 char *EndPtr = NumberBuffer+sizeof(NumberBuffer);
70 char *CurPtr = EndPtr;
71
72 while (N) {
73 *--CurPtr = '0' + char(N % 10);
74 N /= 10;
75 }
76 return write(CurPtr, EndPtr-CurPtr);
77 }
78
79 raw_ostream &raw_ostream::operator<<(long long N) {
80 if (N < 0) {
81 if (OutBufCur >= OutBufEnd)
82 flush_impl();
83 *OutBufCur++ = '-';
84
85 N = -N;
86 }
87
88 return this->operator<<(static_cast(N));
89 }
90
91 raw_ostream &raw_ostream::write(const char *Ptr, unsigned Size) {
92 if (OutBufCur+Size > OutBufEnd)
93 flush_impl();
94
95 // Handle short strings specially, memcpy isn't very good at very short
96 // strings.
97 switch (Size) {
98 case 4: OutBufCur[3] = Ptr[3]; // FALL THROUGH
99 case 3: OutBufCur[2] = Ptr[2]; // FALL THROUGH
100 case 2: OutBufCur[1] = Ptr[1]; // FALL THROUGH
101 case 1: OutBufCur[0] = Ptr[0]; // FALL THROUGH
102 case 0: break;
103 default:
104 // Normally the string to emit is shorter than the buffer.
105 if (Size <= unsigned(OutBufEnd-OutBufStart)) {
106 memcpy(OutBufCur, Ptr, Size);
107 break;
108 }
109
110 // If emitting a string larger than our buffer, emit in chunks. In this
111 // case we know that we just flushed the buffer.
112 while (Size) {
113 unsigned NumToEmit = OutBufEnd-OutBufStart;
114 if (Size < NumToEmit) NumToEmit = Size;
115 assert(OutBufCur == OutBufStart);
116 memcpy(OutBufStart, Ptr, NumToEmit);
117 Ptr += NumToEmit;
118 OutBufCur = OutBufStart + NumToEmit;
119 flush_impl();
120 }
121 break;
122 }
123 OutBufCur += Size;
124 return *this;
125 }
34126
35127 //===----------------------------------------------------------------------===//
36128 // raw_fd_ostream