Move cstddef include to format.cc and refactor Buffer::append

This commit is contained in:
vitaut
2015-11-13 06:52:13 -08:00
parent 3df9bf3a91
commit 7dcf05108e
2 changed files with 8 additions and 7 deletions

View File

@ -34,6 +34,7 @@
#include <climits> #include <climits>
#include <cmath> #include <cmath>
#include <cstdarg> #include <cstdarg>
#include <cstddef> // for std::ptrdiff_t
#if defined(_WIN32) && defined(__MINGW32__) #if defined(_WIN32) && defined(__MINGW32__)
# include <cstring> # include <cstring>
@ -1040,10 +1041,10 @@ void fmt::internal::PrintfFormatter<Char>::format(
ArgConverter<intmax_t>(arg, *s).visit(arg); ArgConverter<intmax_t>(arg, *s).visit(arg);
break; break;
case 'z': case 'z':
ArgConverter<size_t>(arg, *s).visit(arg); ArgConverter<std::size_t>(arg, *s).visit(arg);
break; break;
case 't': case 't':
ArgConverter<ptrdiff_t>(arg, *s).visit(arg); ArgConverter<std::ptrdiff_t>(arg, *s).visit(arg);
break; break;
case 'L': case 'L':
// printf produces garbage when 'L' is omitted for long double, no // printf produces garbage when 'L' is omitted for long double, no

View File

@ -32,7 +32,6 @@
#include <cassert> #include <cassert>
#include <cmath> #include <cmath>
#include <cstddef> // for std::ptrdiff_t
#include <cstdio> #include <cstdio>
#include <algorithm> #include <algorithm>
#include <limits> #include <limits>
@ -484,11 +483,12 @@ class Buffer {
template <typename T> template <typename T>
template <typename U> template <typename U>
void Buffer<T>::append(const U *begin, const U *end) { void Buffer<T>::append(const U *begin, const U *end) {
std::ptrdiff_t num_elements = end - begin; assert(begin <= end);
if (size_ + num_elements > capacity_) std::size_t new_size = size_ + (end - begin);
grow(size_ + num_elements); if (new_size > capacity_)
grow(new_size);
std::copy(begin, end, internal::make_ptr(ptr_, capacity_) + size_); std::copy(begin, end, internal::make_ptr(ptr_, capacity_) + size_);
size_ += num_elements; size_ = new_size;
} }
namespace internal { namespace internal {