llvm.org GIT mirror llvm / ad60f66
Use size_t. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@76069 91177308-0d34-0410-b5e6-96231b3b80d8 Dan Gohman 10 years ago
4 changed file(s) with 24 addition(s) and 24 deletion(s). Raw diff Collapse all Expand all
4646 ///
4747 unsigned Column;
4848
49 virtual void write_impl(const char *Ptr, unsigned Size) {
49 virtual void write_impl(const char *Ptr, size_t Size) {
5050 ComputeColumn(Ptr, Size);
5151 TheStream->write(Ptr, Size);
5252 }
6262 /// ComputeColumn - Examine the current output and figure out
6363 /// which column we end up in after output.
6464 ///
65 void ComputeColumn(const char *Ptr, unsigned Size);
65 void ComputeColumn(const char *Ptr, size_t Size);
6666
6767 public:
6868 /// formatted_raw_ostream - Open the specified file for
9292
9393 /// SetBufferSize - Set the internal buffer size to the specified amount
9494 /// instead of the default.
95 void SetBufferSize(unsigned Size=4096) {
95 void SetBufferSize(size_t Size=4096) {
9696 assert(Size >= 64 &&
9797 "Buffer size must be somewhat large for invariants to hold");
9898 flush();
116116 Unbuffered = true;
117117 }
118118
119 unsigned GetNumBytesInBuffer() const {
119 size_t GetNumBytesInBuffer() const {
120120 return OutBufCur - OutBufStart;
121121 }
122122
154154 // Inline fast path, particulary for constant strings where a
155155 // sufficiently smart compiler will simplify strlen.
156156
157 unsigned Size = strlen(Str);
157 size_t Size = strlen(Str);
158158
159159 // Make sure we can use the fast path.
160160 if (OutBufCur+Size > OutBufEnd)
191191 }
192192
193193 raw_ostream &write(unsigned char C);
194 raw_ostream &write(const char *Ptr, unsigned Size);
194 raw_ostream &write(const char *Ptr, size_t Size);
195195
196196 // Formatted output, see the format() function in Support/Format.h.
197197 raw_ostream &operator<<(const format_object_base &Fmt);
220220 /// \arg Ptr to the underlying stream.
221221 ///
222222 /// \invariant { Size > 0 }
223 virtual void write_impl(const char *Ptr, unsigned Size) = 0;
223 virtual void write_impl(const char *Ptr, size_t Size) = 0;
224224
225225 // An out of line virtual method to provide a home for the class vtable.
226226 virtual void handle();
256256 uint64_t pos;
257257
258258 /// write_impl - See raw_ostream::write_impl.
259 virtual void write_impl(const char *Ptr, unsigned Size);
259 virtual void write_impl(const char *Ptr, size_t Size);
260260
261261 /// current_pos - Return the current position within the stream, not
262262 /// counting the bytes currently in the buffer.
338338 std::ostream &OS;
339339
340340 /// write_impl - See raw_ostream::write_impl.
341 virtual void write_impl(const char *Ptr, unsigned Size);
341 virtual void write_impl(const char *Ptr, size_t Size);
342342
343343 /// current_pos - Return the current position within the stream, not
344344 /// counting the bytes currently in the buffer.
358358 std::string &OS;
359359
360360 /// write_impl - See raw_ostream::write_impl.
361 virtual void write_impl(const char *Ptr, unsigned Size);
361 virtual void write_impl(const char *Ptr, size_t Size);
362362
363363 /// current_pos - Return the current position within the stream, not
364364 /// counting the bytes currently in the buffer.
385385 SmallVectorImpl &OS;
386386
387387 /// write_impl - See raw_ostream::write_impl.
388 virtual void write_impl(const char *Ptr, unsigned Size);
388 virtual void write_impl(const char *Ptr, size_t Size);
389389
390390 /// current_pos - Return the current position within the stream, not
391391 /// counting the bytes currently in the buffer.
1616 /// ComputeColumn - Examine the current output and figure out which
1717 /// column we end up in after output.
1818 ///
19 void formatted_raw_ostream::ComputeColumn(const char *Ptr, unsigned Size) {
19 void formatted_raw_ostream::ComputeColumn(const char *Ptr, size_t Size) {
2020 // Keep track of the current column by scanning the string for
2121 // special characters
2222
120120 char *CurPtr = EndPtr;
121121
122122 while (N) {
123 unsigned x = N % 16;
123 uintptr_t x = N % 16;
124124 *--CurPtr = (x < 10 ? '0' + x : 'a' + x - 10);
125125 N /= 16;
126126 }
152152 return *this;
153153 }
154154
155 raw_ostream &raw_ostream::write(const char *Ptr, unsigned Size) {
155 raw_ostream &raw_ostream::write(const char *Ptr, size_t Size) {
156156 // Group exceptional cases into a single branch.
157157 if (BUILTIN_EXPECT(OutBufCur+Size > OutBufEnd, false)) {
158158 if (Unbuffered) {
202202 // anyway. We should just flush upfront in such cases, and use the
203203 // whole buffer as our scratch pad. Note, however, that this case is
204204 // also necessary for correctness on unbuffered streams.
205 unsigned NextBufferSize = 127;
205 size_t NextBufferSize = 127;
206206 if (OutBufEnd-OutBufCur > 3) {
207 unsigned BufferBytesLeft = OutBufEnd-OutBufCur;
208 unsigned BytesUsed = Fmt.print(OutBufCur, BufferBytesLeft);
207 size_t BufferBytesLeft = OutBufEnd-OutBufCur;
208 size_t BytesUsed = Fmt.print(OutBufCur, BufferBytesLeft);
209209
210210 // Common case is that we have plenty of space.
211211 if (BytesUsed < BufferBytesLeft) {
227227 V.resize(NextBufferSize);
228228
229229 // Try formatting into the SmallVector.
230 unsigned BytesUsed = Fmt.print(&V[0], NextBufferSize);
230 size_t BytesUsed = Fmt.print(&V[0], NextBufferSize);
231231
232232 // If BytesUsed fit into the vector, we win.
233233 if (BytesUsed <= NextBufferSize)
295295 }
296296 }
297297
298 void raw_fd_ostream::write_impl(const char *Ptr, unsigned Size) {
298 void raw_fd_ostream::write_impl(const char *Ptr, size_t Size) {
299299 assert (FD >= 0 && "File already closed.");
300300 pos += Size;
301301 if (::write(FD, Ptr, Size) != (ssize_t) Size)
327327 (colors == SAVEDCOLOR) ? sys::Process::OutputBold(bg)
328328 : sys::Process::OutputColor(colors, bold, bg);
329329 if (colorcode) {
330 unsigned len = strlen(colorcode);
330 size_t len = strlen(colorcode);
331331 write(colorcode, len);
332332 // don't account colors towards output characters
333333 pos -= len;
340340 flush();
341341 const char *colorcode = sys::Process::ResetColor();
342342 if (colorcode) {
343 unsigned len = strlen(colorcode);
343 size_t len = strlen(colorcode);
344344 write(colorcode, len);
345345 // don't account colors towards output characters
346346 pos -= len;
382382 flush();
383383 }
384384
385 void raw_os_ostream::write_impl(const char *Ptr, unsigned Size) {
385 void raw_os_ostream::write_impl(const char *Ptr, size_t Size) {
386386 OS.write(Ptr, Size);
387387 }
388388
400400 flush();
401401 }
402402
403 void raw_string_ostream::write_impl(const char *Ptr, unsigned Size) {
403 void raw_string_ostream::write_impl(const char *Ptr, size_t Size) {
404404 OS.append(Ptr, Size);
405405 }
406406
412412 flush();
413413 }
414414
415 void raw_svector_ostream::write_impl(const char *Ptr, unsigned Size) {
415 void raw_svector_ostream::write_impl(const char *Ptr, size_t Size) {
416416 OS.append(Ptr, Ptr + Size);
417417 }
418418